-
-
Notifications
You must be signed in to change notification settings - Fork 163
Open
Description
Describe the bug
When using P.select(P.string) with multiple patterns in the same .with clause, the handler parameter is not inferred as string.
Instead, it is inferred as the union of the full object shapes, rather than the selected value.
TypeScript playground with a minimal reproduction case
import { match, P } from "ts-pattern";
const obj = {} as unknown;
const message = match(obj)
.with(
{ errors: P.select(P.string) },
{ description: P.select(P.string) },
(message) => {
console.log("message", message);
// β Expected: message is string
// β Actual: message is inferred as object type
return `Please enter ${message.replace("length", "characters")}`;
}
)
.otherwise(() => "");Expected behavior
- The handler parameter should be inferred as
string(fromP.select(P.string)), even when multiple patterns are used.
Actual behavior
- The handler parameter is inferred as the union of the object shapes (
{ errors: string } | { description: string }), not the selectedstring.
Versions
- TypeScript version: 5.9.2
Metadata
Metadata
Assignees
Labels
No labels