npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-exhaustive-match-plugin

v0.0.8

Published

TypeScript Language Service Plugin for generating exhaustive pattern matching

Downloads

6

Readme

ts-exhaustive-match-plugin

npm version npm downloads CI Coverage Status TypeScript License: MIT

A TypeScript Language Service Plugin that generates exhaustive pattern matching for discriminated union types and string literal unions with zero dependencies.

Features

Automatic Exhaustive Pattern Generation: Generates complete if-else chains with TypeScript's satisfies never for compile-time exhaustiveness checking

🎯 Multiple Integration Points:

  • Refactoring: Right-click on identifiers to generate exhaustive matches
  • Auto-completion: Type-ahead support for discriminated union identifiers and property access
  • Quick Fix: Add missing cases to incomplete pattern matches with a single click
  • IntelliSense: Works seamlessly in VS Code, WebStorm, and other TypeScript-enabled editors

🔧 Comprehensive Support:

  • Function parameters (regular, async, methods, arrow functions)
  • Variable declarations (const, let)
  • Standalone identifier expressions
  • If-statement contexts with intelligent completion
  • Type narrowing support (works within type guards)

🏷️ Smart Discriminant Detection: Automatically detects tag property as discriminant (configurable in future versions)

Supported Union Types

Discriminated Unions

type Result =
  | { tag: "success"; data: string }
  | { tag: "error"; message: string }

const result: Result = getResult()
// These cases will get generated:
if (result.tag === "success") {
} else if (result.tag === "error") {
} else {
  result satisfies never
}

String Literal Unions

type Status = "loading" | "success" | "error"

const status: Status = getStatus()
// These cases will get generated:
if (status === "loading") {
} else if (status === "success") {
} else if (status === "error") {
} else {
  status satisfies never
}

Supported Contexts

The plugin generates exhaustive matches in these contexts:

// Function parameters
function handle(result: Result) {
  // Cursor on 'result' → generates exhaustive match
}

// Variable declarations
const result: Result = getResult()
// Cursor on 'result' → generates exhaustive match

// Standalone expressions
result // Cursor here → generates exhaustive match

// If statements with smart completion
if (result. // Auto-completes with exhaustive match for discriminated unions
if (status  // Auto-completes with exhaustive match for string literal unions

Installation

Install the plugin as a development dependency:

npm install --save-dev ts-exhaustive-match-plugin

Configuration

Add the plugin to your tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-exhaustive-match-plugin"
      }
    ]
  }
}

Usage

Via Refactoring (Right-click menu)

  1. Place your cursor on a discriminated union identifier
  2. Right-click and select "Refactor..."
  3. Choose "Generate exhaustive match"

Via Auto-completion

  1. Type a discriminated union identifier followed by .
  2. Select the exhaustive match completion from the suggestion list
  3. Tab through the generated placeholder blocks

Via Quick Fix

When you have an incomplete pattern match:

type Status = "idle" | "pending" | "done"
const status: Status = getStatus()

if (status === "idle") {
  // Handle idle
} else {
  status satisfies never // TypeScript error: Type '"pending" | "done"' does not satisfy 'never'
}
  1. Place your cursor on the satisfies never expression
  2. Use the quick fix shortcut (Cmd+. on Mac, Ctrl+. on Windows/Linux)
  3. Select "Add missing cases: pending, done"
  4. The plugin will automatically add the missing cases

Generated Output

For a discriminated union like:

type ApiResponse =
  | { tag: "loading" }
  | { tag: "success"; data: User[] }
  | { tag: "error"; error: string }

function handleResponse(response: ApiResponse) {
  // Generated exhaustive match:
  if (response.tag === "loading") {
    // Handle loading
  } else if (response.tag === "success") {
    // Handle success - data is typed as User[]
  } else if (response.tag === "error") {
    // Handle error - error is typed as string
  } else {
    response satisfies never // Ensures exhaustiveness
  }
}

Editor Support

  • VS Code: Full support with IntelliSense and refactoring
  • WebStorm/IntelliJ: Works with TypeScript Language Service
  • Vim/Neovim: Via TypeScript LSP clients
  • Emacs: Via TypeScript mode

Requirements

  • TypeScript 5.0 or higher
  • A TypeScript-enabled editor or IDE

Future Enhancements

  • Configurable discriminant property names

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT