Skip to content

Update dependency ts-pattern to ^5.9.0#10

Open
renovate[bot] wants to merge 1 commit intomasterfrom
renovate/ts-pattern-5.x
Open

Update dependency ts-pattern to ^5.9.0#10
renovate[bot] wants to merge 1 commit intomasterfrom
renovate/ts-pattern-5.x

Conversation

@renovate
Copy link

@renovate renovate bot commented Dec 19, 2023

This PR contains the following updates:

Package Change Age Confidence
ts-pattern ^5.0.5^5.9.0 age confidence

Release Notes

gvergnaud/ts-pattern (ts-pattern)

v5.9.0

Compare Source

New features

P.record patterns

To match a Record<Key, Value> (an object with consistent key and value types), you can use P.record(keyPattern, valuePattern).
It takes a sub-pattern to match against the key, a sub-pattern to match against the value, and will match if all entries in the object
match these two sub-patterns.

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

type Input = Record<string, number>;

const input: Input = {
  alice: 100,
  bob: 85,
  charlie: 92,
};

const output = match(input)
  .with(P.record(P.string, P.number), (scores) => `All user scores`)
  .with(P.record(P.string, P.string), (names) => `All user names`)
  .otherwise(() => '');

console.log(output);
// => "All user scores"

You can also use P.record with a single argument P.record(valuePattern), which assumes string keys:

const userProfiles = {
  alice: { name: 'Alice', age: 25 },
  bob: { name: 'Bob', age: 30 },
};

const output = match(userProfiles)
  .with(
    P.record({ name: P.string, age: P.number }),
    (profiles) => `User profiles with name and age`
  )
  .otherwise(() => 'Different format');

console.log(output);
// => "User profiles with name and age"

When using P.select in record patterns, you can extract all keys or all values as arrays:

const data = { a: 1, b: 2, c: 3 };

const keys = match(data)
  .with(P.record(P.string.select(), P.number), (keys) => keys)
  .otherwise(() => []);

const values = match(data)
  .with(P.record(P.string, P.number.select()), (values) => values)
  .otherwise(() => []);

console.log(keys); // => ['a', 'b', 'c']
console.log(values); // => [1, 2, 3]

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.8.0...v5.9.0

v5.8.0

Compare Source

TS-Pattern v5.8.0 Release Notes

New Feature: .narrow() Method for Deep Type Narrowing

.narrow() gives you fine-grained control over type narrowing of deeply nested union types during pattern matching.

What is .narrow()?

The .narrow() method allows you to explicitly narrow the input type to exclude all values that have been handled by previous patterns. This is especially useful when working with:

  • Deeply nested union types
  • Nullable properties at any nesting level
  • Complex type structures where you need precise type information
When to Use .narrow()

By default, TS-Pattern automatically narrows top-level union types as you pattern match. However, for deeply nested types, this narrowing doesn't happen automatically to maintain optimal TypeScript performance. The .narrow() method gives you explicit control over when to perform this more computationally expensive operation.

Example Usage
type Input = { user: { role: 'admin' | 'editor' | 'viewer' } };

declare const input: Input;

const result = match(input)
  .with({ user: { role: 'admin' } }, handleAdmin)
  .narrow() // Explicitly narrow remaining cases
  .with({ user: { role: 'editor' } }, handleEditor)
  .narrow() // Narrow again if needed
  .otherwise((remaining) => {
    // remaining.user.role is now precisely 'viewer'
    handleViewer(remaining);
  });
Additional Improvements
  • Improvements to release scripts
  • Updated dependencies

Full Changelog: gvergnaud/ts-pattern@v5.7.1...v5.8.0

PRs

v5.7.1

Compare Source

Type inference bug fixes

This new release fixes the following bug in exhaustiveness checking when matching on optional properties:

type Input = { type?: 'one' } | { type: 'two' };

const f1 = (input: Input) =>
  match(input)
    .with({ type: 'one' }, () => {})
    .with({ type: 'two' }, () => {})
    .exhaustive(); // shouldn't type-check, but does 👎

const f2 = (input: Input) =>
  match(input)
    .with({ type: 'one' }, () => {})
    .with({ type: 'two' }, () => {})
    .with({ type: undefined }, () => {}) // <- the type key needs to be present.
    .exhaustive();  // shouldn't type-check, but does 👎

These two cases don't type check anymore. They fail with a NonExhaustiveError<{ type?: undefined; }>. To fix it, you should do:

type Input = { type?: 'one' } | { type: 'two' };

const f = (input: Input) =>
  match(input)
    .with({ type: 'one' }, () => {})
    .with({ type: 'two' }, () => {})
    .with({ type: P.optional(undefined) }, () => {}) // <- the type property may not be there
    .exhaustive(); // ✅

This is a purely type-level change, the runtime behavior is still the same.

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.7.0...v5.7.1

v5.7.0

Compare Source

New feature

Exhaustive callback

By default, .exhaustive() will throw an error if the input value wasn't handled by any .with(...) clause. This should only happen if your types are incorrect.

It is possible to pass your own handler function as a parameter to decide what should happen if an unexpected value has been received. You can for example throw your own custom error:

match(...)
  .with(...)
  .exhaustive((unexpected: unknown) => {
    throw MyCustomError(unexpected);
  })

Or log an error and return a default value:

match<string, number>(...)
  .with(P.string, (str) => str.length)
  .exhaustive((notAString: unknown) => {
    console.log(`received an unexpected value: ${notAString}`);
    return 0;
  })

Improved narrowing for isMatching

isMatching didn't have full feature parity with match in terms of type narrowing, but now does.

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.6.2...v5.7.0

v5.6.2

Compare Source

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.6.1...v5.6.2

v5.6.1

Compare Source

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.6.0...v5.6.1

v5.6.0

Compare Source

This release contains two changes:

Typecheck pattern when using isMatching with 2 parameter.

It used to be possible to pass a pattern than could never match to isMatching. The new version checks that the provide pattern does match the value in second parameter:

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

const fn = (food: Pizza | Sandwich) => {
    if (isMatching({ type: 'oops' }, food)) {
        //                  👆 used to type-check, now doesn't!
    }
}
Do not use P.infer as an inference point

When using P.infer<Pattern> to type a function argument, like in the following example:

const getWithDefault = <T extends P.Pattern>(
  input: unknown,
  pattern: T,
  defaultValue: P.infer<T> //  👈
): P.infer<T> =>
  isMatching(pattern, input) ? input : defaultValue

TypeScript could get confused and find type errors in the wrong spot:

const res = getWithDefault(null, { x: P.string }, 'oops') 
//                                     👆           👆 type error should be here
//                                 but it's here 😬

This new version fixes this problem.

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.5.0...v5.6.0

v5.5.0

Compare Source

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.4.0...v5.5.0

v5.4.0

Compare Source

The main thing — Faster type checking 🚀

This release brings a significant perf improvement to exhaustiveness checking, which led to a ~16% decrease in the time to type-check the full test suite of TS-Pattern:

Category Before After Evolution (%)
Instantiations 6,735,991 4,562,378 -32.33%
Memory used 732,233K 746,454K 1.95%
Assignability cache size 209,959 205,926 -1.92%
Identity cache size 28,093 28,250 0.56%
Check time 5.78s 4.83s -16.44%

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.3.1...v5.4.0

v5.3.1

Compare Source

Pattern-matching on symbol keys

Symbols used to be ignored in object patterns. They are now taken into account:

const symbolA = Symbol('symbol-a');
const symbolB = Symbol('symbol-b');

const obj = { [symbolA]: { [symbolB]: 'foo' } };
    
if (isMatching({ [symbolA]: { [symbolB]: 'bar' } }, obj)) {
   //  👆 Used to return true, now returns false!
   
   //  Since TS-Pattern wasn't reading symbols, this pattern used to be equivalent
   //  to the `{}` pattern that matches any value except null and undefined.
}

.exhaustive now throws a custom error

People have expressed the need to differentiate runtime errors that .exhaustive() might throw when the input is of an unexpected type from other runtime errors that could have happened in the same match expression. It's now possible with err instanceof NonExhaustiveError:

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

const fn = (input: string | number) => {
  return match(input)
    .with(P.string, () => "string!")
    .with(P.number, () => "number!")
    .exhaustive()
}

try {
  fn(null as string) // 👈 💥 
} catch (e) {
  if (e instanceof NonExhaustiveError) {
    // The input was invalid
  } else {
    // something else happened
  }
}

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.2.0...v5.3.1

v5.3.0

Compare Source

v5.2.0

Compare Source

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: gvergnaud/ts-pattern@v5.1.2...v5.2.0

v5.1.2

Compare Source

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

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.1.1...v5.1.2

v5.1.1

Compare Source

What's Changed

Full Changelog: gvergnaud/ts-pattern@v5.1.0...v5.1.1

v5.1.0

Compare Source

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: gvergnaud/ts-pattern@v5.0.8...v5.1.0

v5.0.8

Compare Source

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

Full Changelog: gvergnaud/ts-pattern@v5.0.6...v5.0.8

v5.0.7

Compare Source

v5.0.6

Compare Source

Close issue issues

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

What's Changed

New Contributors

Full Changelog: gvergnaud/ts-pattern@v5.0.5...v5.0.6


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from a760f12 to c3eee92 Compare February 16, 2024 05:40
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.0.6 Update dependency ts-pattern to ^5.0.8 Feb 16, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from c3eee92 to a700f73 Compare April 1, 2024 08:35
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.0.8 Update dependency ts-pattern to ^5.1.0 Apr 1, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from a700f73 to 86e65eb Compare April 7, 2024 05:55
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.1.0 Update dependency ts-pattern to ^5.1.1 Apr 7, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 86e65eb to a8fffa6 Compare May 24, 2024 05:34
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.1.1 Update dependency ts-pattern to ^5.1.2 May 24, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from a8fffa6 to 8c92173 Compare June 13, 2024 23:43
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.1.2 Update dependency ts-pattern to ^5.2.0 Jun 13, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 8c92173 to 7fc90f2 Compare August 12, 2024 02:45
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.2.0 Update dependency ts-pattern to ^5.3.1 Aug 12, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 7fc90f2 to 3788189 Compare September 26, 2024 02:50
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.3.1 Update dependency ts-pattern to ^5.4.0 Sep 26, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 3788189 to a292701 Compare October 15, 2024 05:47
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.4.0 Update dependency ts-pattern to ^5.5.0 Oct 15, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from a292701 to be0177e Compare December 16, 2024 02:09
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.5.0 Update dependency ts-pattern to ^5.6.0 Dec 16, 2024
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from be0177e to 81b1576 Compare January 20, 2025 07:36
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.6.0 Update dependency ts-pattern to ^5.6.1 Jan 20, 2025
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.6.1 Update dependency ts-pattern to ^5.6.2 Jan 24, 2025
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 81b1576 to 10b5e2a Compare January 24, 2025 07:04
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.6.2 Update dependency ts-pattern to ^5.7.0 Mar 29, 2025
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 10b5e2a to 088d375 Compare March 29, 2025 11:57
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 088d375 to 073c0a3 Compare May 24, 2025 11:46
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.7.0 Update dependency ts-pattern to ^5.7.1 May 24, 2025
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 073c0a3 to b7ab719 Compare July 26, 2025 20:02
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.7.1 Update dependency ts-pattern to ^5.8.0 Jul 26, 2025
@renovate renovate bot changed the title Update dependency ts-pattern to ^5.8.0 Update dependency ts-pattern to ^5.9.0 Nov 19, 2025
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from b7ab719 to 219692c Compare November 19, 2025 23:47
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 219692c to 4a4e7b6 Compare December 31, 2025 11:35
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 4a4e7b6 to 52a3641 Compare February 3, 2026 16:03
@renovate renovate bot force-pushed the renovate/ts-pattern-5.x branch from 52a3641 to cb1c132 Compare February 14, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants