microsoft / microsoft/TypeScript

`Omit` causes function to lose contextual typing

Abierto
#63,225 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Empieza reproduciendo el ejemplo de Playground enlazado con TypeScript 5.9.3 y 6.0-rc, comparando la inferencia contextual con y sin Omit y con el tipo mapeado identidad. Rastrea el flujo de comprobación de tipos para el tipo mapeado envuelto en Omit; se considera terminado cuando el parámetro del callback se infiere como string y el error implicit-any notificado ya no se produce.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.