microsoft / microsoft/TypeScript

Inference from result of generic function no longer produces a union

オープン
#63,227 コメント 1 件 リアクション 0 件 担当者 1 名 @ahejlsberg が担当を希望しています GitHub で見る
Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。