github gvergnaud/ts-pattern v2.2.2

latest releases: v5.1.1, v5.1.0, v5.0.8...
3 years ago

Support for multiple patterns

You can now provide up to 5 patterns to .with(), and the code branch will be chosen if your input matches one of these patterns.

Example:

match<Country>('France')
      .exhaustive()
      // if it matches one of these patterns
      .with('France', 'Germany', 'Spain', () => 'Europe')
      .with('USA', () => 'America')
      .run();

    match<Country>('France')
      .exhaustive()
      .with('Germany', 'Spain', () => 'Europe')
      .with('USA', () => 'America')
      // doesn't compile! 'France' is missing
      .run();

Don't miss a new ts-pattern release

NewReleases is sending notifications on new releases.