Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
import { match, P } from 'ts-pattern';
const userProfiles = {
const data = { a: 1, b: 2, c: 3 };
- Fix: Add missing public/index.html to gif-fetcher example by @ rio-sung-ks in #330
- set sideEffects to false to make ts-pattern tree shakable by @ timvandam in #317
- feat(P.record): implementation by @ gvergnaud in #332
- @ rio-sung-ks made their first contribution in #330
- @ timvandam made their first contribution in #317
-
5.8.0 - 2025-07-26
- Deeply nested union types
- Nullable properties at any nesting level
- Complex type structures where you need precise type information
type Input = { user: { role: 'admin' | 'editor' | 'viewer' } };
- Improvements to release scripts
- Updated dependencies
- feat: .narrow() method & typechecking perf improvement by @ gvergnaud in #261
from ts-pattern GitHub release notesNew features
P.recordpatternsTo match a
Record<Key, Value>(an object with consistent key and value types), you can useP.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.
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.recordwith a single argumentP.record(valuePattern), which assumes string keys: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.selectin record patterns, you can extract all keys or all values as arrays: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
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: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
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
Full Changelog: v5.7.1...v5.8.0
PRs
Important
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: