patterns of type `P.Pattern` do not work
Author: adamschoenemannCreated Dec 12, 2025Updated Dec 12, 2025
Describe the bug
If you have a pattern for a type A and you type it as P.Pattern<A>, using it in any match will cause the inferred type in the handler to be MixedNamedAndAnonymousSelectError
TypeScript example
type A = { type: "A"; a: string };
const patternA: P.Pattern<A> = {
type: "A" as const,
a: P.string,
};
const testPatterMatch = (x: A) => {
return match(x)
// x has type MixedNamedAndAnonymousSelectError<"Mixing named selections (`select(\"name\")`) and anonymous selections (`select()`) is forbiden. Please, only use named selections.">
.with(patternA, (x) => `Matched A with b: ${x.a}`)
.exhaustive();
}Versions
- TypeScript version: 5.9.3
- ts-pattern version: 5.9.0
Source: gvergnaud/ts-pattern