Skip to content

[Snyk] Upgrade ts-pattern from 5.8.0 to 5.9.0#11

Open
waspeer wants to merge 1 commit intomainfrom
snyk-upgrade-92f208ffa396a95f3f2c4b0a9ae467dc
Open

[Snyk] Upgrade ts-pattern from 5.8.0 to 5.9.0#11
waspeer wants to merge 1 commit intomainfrom
snyk-upgrade-92f208ffa396a95f3f2c4b0a9ae467dc

Conversation

@waspeer
Copy link
Owner

@waspeer waspeer commented Nov 21, 2025

snyk-top-banner

Snyk has created this PR to upgrade ts-pattern from 5.8.0 to 5.9.0.

ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.


  • The recommended version is 1 version ahead of your current version.

  • The recommended version was released a month ago.

Release notes
Package name: ts-pattern
  • 5.9.0 - 2025-10-26

    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: v5.8.0...v5.9.0

  • 5.8.0 - 2025-07-26

    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: v5.7.1...v5.8.0

    PRs

    • feat: .narrow() method & typechecking perf improvement by @ gvergnaud in #261
from ts-pattern GitHub release notes

Important

  • Check the changes in this PR to ensure they won't cause issues with your project.
  • This PR was automatically created by Snyk using the credentials of a real user.

Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.

For more information:

Snyk has created this PR to upgrade ts-pattern from 5.8.0 to 5.9.0.

See this package in npm:
ts-pattern

See this project in Snyk:
https://app.snyk.io/org/waspeer/project/04fbef6f-bbe6-4baa-8416-c4cccf0c1056?utm_source=github&utm_medium=referral&page=upgrade-pr
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.

2 participants