Skip to content

Releases: gvergnaud/ts-pattern

v5.2.0

12 Jun 12:32
Compare
Choose a tag to compare

The main thing

new P.string.length(n) pattern

P.string.length(len) matches strings with exactly len characters.

const fn = (input: string) =>
  match(input)
    .with(P.string.length(2), () => '🎉')
    .otherwise(() => '❌');

console.log(fn('ok')); // logs '🎉'

What's Changed

New Contributors

Full Changelog: v5.1.2...v5.2.0

v5.1.2

23 May 14:44
7160317
Compare
Choose a tag to compare

The main thing

When combining P.nonNullable and P.nullish, you should get an exhaustive pattern matching expression, but the following case was incorrectly considered non-exhaustive:

declare const input: {
  nested: string | number | null | undefined;
};

const res = match(input)
  .with({ nested: P.nonNullable }, (x) => {/* ... */})
  .with({ nested: P.nullish }, (x) => {/* ... */})
  // should type-check
  .exhaustive();

This is fixed now.

What's Changed

  • build(deps): bump postcss and react-scripts in /examples/gif-fetcher by @dependabot in #243
  • build(deps): bump loader-utils and react-scripts in /examples/gif-fetcher by @dependabot in #242
  • build(deps): bump jsdom and react-scripts in /examples/gif-fetcher by @dependabot in #241
  • build(deps): bump tough-cookie and react-scripts in /examples/gif-fetcher by @dependabot in #240
  • build(deps): bump shell-quote and react-scripts in /examples/gif-fetcher by @dependabot in #239
  • chore: add P.map specific jsdoc for P.map by @momentiris in #245
  • build(deps-dev): bump ejs from 3.1.9 to 3.1.10 in /examples/gif-fetcher by @dependabot in #249
  • build(deps-dev): bump ejs from 3.1.9 to 3.1.10 by @dependabot in #248
  • fix: exhaustive checking with nested P.nonNullable patterns by @gvergnaud in #252

New Contributors

Full Changelog: v5.1.1...v5.1.2

v5.1.1

06 Apr 21:43
19ae81e
Compare
Choose a tag to compare

What's Changed

  • Fix(P.nonNullable): narrowing of unions of objects by @gvergnaud in #237

Full Changelog: v5.1.0...v5.1.1

v5.1.0

31 Mar 20:40
Compare
Choose a tag to compare

New features

P.nonNullable wildcard

Add a new P.nonNullable pattern that will match any value except null or undefined.

import { match, P } from 'ts-pattern';

const input = null;

const output = match<number | null | undefined>(input)
  .with(P.nonNullable, () => 'it is a number!')
  .otherwise(() => 'it is either null or undefined!');

console.log(output);
// => 'it is either null or undefined!'

Closes #60 #154 #190 and will be a work-around for #143.

What's Changed

Full Changelog: v5.0.8...v5.1.0

v5.0.8

15 Feb 15:25
Compare
Choose a tag to compare

The main thing

This release includes type narrowing improvement to isMatching when used in its curried form:

type Pizza = { type: 'pizza', topping: string };
type Sandwich = { type: 'sandwich', condiments: string[] }
type Food =  Pizza | Sandwich;

declare const food: Food

const isPizza = isMatching({ type: 'pizza' })

if (isPizza(food)) {
  x  // Used to  infer `food` as `Food`, no infers `Pizza`
}

This also improves type checking performance for complex patterns and fixes a small bug in the ES5 build of TS-Pattern.

What's Changed

  • perf: support exhaustive match on larger unions by @gvergnaud in #214
  • fix: make isMatching(p) infer the pattern as a const type parameter by @gvergnaud in #221
  • fix: Make sure regeneratorRuntime isn't included in the cjs build by @gvergnaud in #224

Full Changelog: v5.0.6...v5.0.8

v5.0.6

03 Dec 02:27
8f2158f
Compare
Choose a tag to compare

Close issue issues

  • Exhaustive matching fix for read only arrays #206
  • Fix incorrect JS docs #196

What's Changed

New Contributors

Full Changelog: v5.0.5...v5.0.6

v5.0.5

06 Aug 21:41
Compare
Choose a tag to compare

Bug fixes

The P module was mistakenly exposing some pattern methods that were intended to be namespaced by type. This release fixes this problem.

If you happened to use on of those following methods, here is where to find them now:

- P.between
+ P.number.between
- P.lt
+ P.number.lt
- P.gt
+ P.number.gt
- P.lte
+ P.number.lte
- P.gte
+ P.number.gte
- P.int
+ P.number.int
- P.finite
+ P.number.finite
- P.positive
+ P.number.positive
- P.negative
+ P.number.negative
- P.betweenBigInt
+ P.bigint.between
- P.ltBigInt
+ P.bigint.lt
- P.gtBigInt
+ P.bigint.gt
- P.lteBigInt
+ P.bigint.lte
- P.gteBigInt
+ P.bigint.gte
- P.positiveBigInt
+ P.bigint.positive
- P.negativeBigInt
+ P.bigint.negative

v5.0.4

19 Jul 15:49
Compare
Choose a tag to compare

What's Changed

  • 🐛 fix: Accept branded primitive types as patterns by @gvergnaud in #180

Full Changelog: v5.0.3...v5.0.4

v5.0.3

14 Jul 11:19
a612fa2
Compare
Choose a tag to compare

What's Changed

  • 🐛 fix: Allow re-exporting patterns from ES Modules by @gvergnaud in #175

Full Changelog: v5.0.2...v5.0.3

v5.0.2

13 Jul 17:08
Compare
Choose a tag to compare

What's Changed

  • fix(P.infer): Fix inference of arrays containing tuples in c52af6a
  • refactoring: simplify selection types in 1b7a36b
  • perf: runtime perf improvement in .with in 9b27384
  • fix: use Symbol.for to make sure two concurrent versions of ts-pattern are compatible with one-another in d6d2e23
  • docs: fix typo by @juicyjusung in #170

New Contributors

Full Changelog: v5.0.0...v5.0.2