microsoft / microsoft/TypeScript

`Omit` causes function to lose contextual typing

Offen
#63,225 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Needs Investigation
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

### 🔎 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)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, das verlinkte Playground-Beispiel mit TypeScript 5.9.3 und 6.0-rc zu reproduzieren, und vergleiche die kontextuelle Typisierung mit und ohne Omit sowie mit dem Identitäts-Mapped-Type. Verfolge den Typprüfpfad für den mit Omit umschlossenen Mapped-Type; als abgeschlossen gilt die Aufgabe, wenn der Parameter des Callbacks als string inferiert wird und der gemeldete implicit-any-Fehler nicht mehr auftritt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.