microsoft / microsoft/TypeScript
`Omit` causes function to lose contextual typing
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- PR merge metrics
- PR metrics pending
Description
### 🔎 Search Terms
implicit any contextual type
### 🕗 Version & Regression Information
- This changed between versions 5.9.3 and 6.0 - rc
### ⏯ Playground Link
[Playground Link](https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260309#code/CYUwxgNghgTiAEEQBd4A8Bc8De8BmArgHZjICWA9kVgM7IxlEDm8AvgLABQIaADhTFTIAnrwQBBGjRCCoAIyQBlZFGQgAPABUAfPAC8OLvGPwA2gAV4jeAGsQwinnib4UGvHMBdLAAoAblAQBCBYmhaeAJT6un4UZMAA3FwcnKCQsAiEJORUrlIyyAD6dKoaLjxqRMDuFHIAVuDI2j4UoQA08CVqWJLSsgogyqVa2hFYsfFJnG59RV0gPmgd2EYmWaSU1PB+0Ths8AD0B9tW7nQMzMkRXDep4NBw+MQbuTMFxSpqhXJQwFrwFRAVRq9UazVazg68ywAHkALZkZDqXoFeRKT5lbQdABE2NG4ziiS4b0EH1K31+i2Wq2M6xyWx2el0uFYh2OMhgAngAFoTmR3GQ4bwIGRSBBhK4iMIrkA)
### 💻 Code
```ts
declare let x: { function: string }
export type AssertableState = {
[P in keyof T as P]: (value: T[P]) => void;
}
declare function assert_state(o: T, state: AssertableState): void;
assert_state(x, {
function: v => { } // v is string
})
declare function assert_state_bad(o: T, state: Omit, "">): void;
assert_state_bad(x, {
function: v => { } // error - v is implictly any
})
```
### 🙁 Actual behavior
The call to `assert_state_bad` fails because `v` is implicitly typed as `any`
### 🙂 Expected behavior
Either should pass as in 5.9.3
### Additional information about the issue
- Works without the `Omit`
- Works without the `as P` in the mapped type. (original mapping was more complicated, but identity mapping seems to trigger it too)
Contributor guide
Research direction
Start by reproducing the linked Playground example with TypeScript 5.9.3 and 6.0-rc, comparing contextual typing with and without Omit and with the identity mapped type. Trace the type-checking path for the Omit-wrapped mapped type; done means the callback parameter is inferred as string and the reported implicit-any failure no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100