microsoft / microsoft/TypeScript
`Omit` causes function to lose contextual typing
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 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)
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo l’esempio Playground collegato con TypeScript 5.9.3 e 6.0-rc, confrontando la tipizzazione contestuale con e senza Omit e con il tipo mappato identità. Traccia il percorso del controllo dei tipi per il tipo mappato racchiuso in Omit; il lavoro è completato quando il parametro del callback viene inferito come string e l’errore implicit-any segnalato non si verifica più.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100