microsoft / microsoft/TypeScript

Inference from result of generic function no longer produces a union

Abierto
#63,227 1 comentario 0 reacciones 1 asignado Ver en GitHub

@ahejlsberg ya está trabajando en esto.

Desde el 11/3/2026.

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

function inference

### 🕗 Version & Regression Information

- This changed between versions 5.9 and 6.0-rc

### ⏯ Playground Link

[Playground Link](https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260310#code/LAKAJgpgxgNghgJwgAgGYFcB2UAuBLAe02UggAcBRAR3ThgB4AVAPgAo5daYA1O9CAFzJGAGmQQAHmWg4IYXjH5DRyALYQAzhrgBzCAH4hGnAjyYdASiEA3AnjABuUJFiIUGbPiLIoBVWQ4cJjYCACMAK2UrYWRnCHJqLlZff0DWAG9kOCEAIgALCBgYAhyxUKEsSFQzOWQAXwsxdNBkVqzcgqKSkVAGpxA4hJo6DPbkfMLi0uRy5EqIasxauqaWtuzxzqmekD6gA)

### 💻 Code

```ts

declare function deepEqual(actualValue: T, expectedValue: T, message?: string): void;
declare function compact(obj: T): T
// Error
deepEqual(compact({ a: "hello", b: undefined }), {
a: "hello",
});
// Ok
deepEqual({ a: "hello", b: undefined }, {
a: "hello",
});
```

### 🙁 Actual behavior

First call fails. `T` for deepEqaul is inferred to `{ a: string, b: undefined;}` instead of `{
a: string;
b: undefined;
} | {
a: string;
b?: undefined;
}` as it is for the second call that succeeds. In 5.9, `T` is inferred to `{
a: string;
}` which is not really great either.

### 🙂 Expected behavior

Both calls should pass type checking

### Additional information about the issue

_No response_

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.