Incorrect Partial Type + Discriminated Union Exhaustion Typecheck
**Describe the bug**
In the below example, the exhaustive check is failing but all cases appear to be covered and versions up to 5.6 work as expected
**TypeScript playground with a minimal reproduction case**
```typescript
type Inner =
| {
discriminator: 'a';
context: string;
}
| {
discriminator: 'b';
context: boolean;
}
| {
discriminator: 'c';
context: Date;
};
type T = {
id: string;
} & Partial<Inner>;
const parse = (x: T | undefined) => {
return match(x)
.with(undefined, () => null)
.with({ discriminator: P.nullish }, () => null)
.with(
{ discriminator: 'a', context: P.select() },
(accountName) => accountName
)
.with(
{ discriminator: 'b', context: P.select() },
(openedDate) => openedDate
)
.with(
{ discriminator: 'c', context: P.select() },
(isKnown) => isKnown
)
.exhaustive(); // claims that there is an unhandled case
};
```
**Versions**
- TypeScript version: 5.9.3
- ts-pattern version: 5.9.0 (last working minor version is 5.6)
- environment: VSCode, Chrome, CodeSandbox
关闭于 2025-12-01 1 条评论