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

@danilqa/eslint-plugin-ts-pattern

v0.0.3

Published

ESLint plugin: warn when `if` is used on string-literal union types instead of ts-pattern's exhaustive `match`

Readme

@danilqa/eslint-plugin-ts-pattern

Warns when you compare a string-literal union type with === / !==, and points you at ts-pattern's exhaustive match instead.

Problem

type State = 'failed' | 'success' | 'pending'

interface Payment {
  state: State
}

function describe(payment: Payment) {
  // Case 1.
  // When "State" later grows a "refunded" variant, the compiler does not flag this "if". The branch silently misses
  // the new case — and so does every other `if` block scattered across the codebase.
  if (payment.state === 'failed') return 'a'

  // Case 2.
  // We implicitly convert union to "boolean" type instead of covering all cases now and in the future. Added 'refunded'?
  // It will be implicitly mached to "b" and we won't notice.
  return payment.state === 'failed' ? 'a' : 'b'
}

Solution

import { match } from 'ts-pattern'

function describe(payment: Payment) {
  return match(payment.state)
    .with('failed', () => 'a')
    .with('success', () => 'b')
    .with('pending', () => 'c')
    .exhaustive()
}

.exhaustive() makes a missing case a compile-time error. Adding 'refunded' to State immediately fails the build everywhere it isn't handled.

Install

npm i --dev @danilqa/eslint-plugin-ts-pattern
yarn add -D @danilqa/eslint-plugin-ts-pattern
pnpm add -D @danilqa/eslint-plugin-ts-pattern

Usage

import tsPattern from '@danilqa/eslint-plugin-ts-pattern'

export default [
  {
    // ...
    plugins: { 'ts-pattern': tsPattern },
    rules: {
      'ts-pattern/prefer-match-on-union': 'warn',
    },
    // ...
  },
]

Rules

type State = 'failed' | 'success' | 'pending'
let state: State

The rule fires on any === / !== comparison between a string-literal union and a literal — no matter where the expression lives (if, ternary, return, variable initializer, function argument, etc.). The one exception is while / do-while loop tests, which describe iteration rather than branching and have no match() equivalent.

| Case | Example | Fires | | --------------------------------------------------- | ------------------------------------- | :---: | | String-literal union, === with literal | if (state === 'failed') {} | ✅ | | String-literal union, !== with literal | if (state !== 'failed') {} | ✅ | | Literal on the left side | if ('failed' === state) {} | ✅ | | Ternary on a string-literal union | state === 'failed' ? 1 : 0 | ✅ | | Member access into a union property | if (payment.state === 'failed') {} | ✅ | | Optional chain on non-nullable receiver | if (payment?.state === 'failed') {} | ✅ | | Optional / nullable property (State \| undefined) | if (payment.state === 'failed') {} | ✅ | | Inside && / \|\| / ! | if (s === 'failed' \|\| other) {} | ✅ | | Variable initializer | const isFailed = s === 'failed' | ✅ | | return expression | return s === 'failed' | ✅ | | Function argument / object value / array element | log(s === 'failed') | ✅ | | Plain string operand | if (s === 'hi') {} | ❌ | | Single-member literal type ('only') | if (x === 'only') {} | ❌ | | Number- or boolean-literal union (1 \| 2) | if (n === 1) {} | ❌ | | Mixed-type union ('a' \| number) | if (m === 'a') {} | ❌ | | Loose equality (== / !=) | if (s == 'failed') {} | ❌ | | Both operands are non-literal | if (a === b) {} | ❌ | | while / do-while loop test | while (s !== 'failed') {} | ❌ | | switch statement | switch (s) { case 'failed': … } | ❌ |