github gvergnaud/ts-pattern v2.0.1-next.2
Exhaustive pattern matching RC

latest releases: v5.1.1, v5.1.0, v5.0.8...
pre-release3 years ago

This pre-release introduces a new API to opt into exhaustive checking, to let typescript make sure that all possible cases are handled and that your code won't throw at runtime.

Here is an example of this new API:

type Input = { kind: 'none' } | { kind: 'some'; value: number };

// This compiles:
match<Input>({ kind: 'some', value: 3 })
        .exhaustive()
        .with({ kind: 'some' }, ({ value }) => value)
        .with({ kind: 'none' }, () => 0)
        .run();

// This doesn't
match<Input>({ kind: 'some', value: 3 })
        .exhaustive()
        .with({ kind: 'some' }, ({ value }) => value)
        .run();

This is a major version because it uses some features of the type system that were introduced in TS v4.x, like variadic tuples, and recursive conditional types. People using earlier versions of TS will need to upgrade in order to use ts-pattern v2+.

Don't miss a new ts-pattern release

NewReleases is sending notifications on new releases.