microsoft / microsoft/TypeScript
Type inference regression on function calls not saved to variables, due to #61668
還沒有人認領這個 Issue。
- 主要語言
- Go
- 星號
- 111k
- 分支
- 14.3k
- 平均合併
- 2 天 4 小時
- 30 天內合併 PR
- 132
描述
🔎 Search Terms
61668 inference overload regression tuple
🕗 Version & Regression Information
- This changed in commit or PR #61668
⏯ Playground Link
💻 Code
declare function getNum(): Promise<number>;
declare function getStr(): Promise<string>;
declare function useTuple(tuple: [number, string]): void;
const p = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);
🙁 Actual behavior
The Promise.all infers to Promise<(number|string)[]>.
🙂 Expected behavior
The Promise.all should infer Promise<[number, string]>.
Additional information about the issue
This only happens when the Promise.all call is directly returned. If I instead write
const p = Promise.all([getNum(), getStr()]);
return p;
then it infers the tuple correctly again, even without doing anything that would suggest it should infer the type differently.
This PR also impacted inference of enums: in another example, I pass {mode: new Subject(Mode.A)} into a function that fails because it infers Subject<Mode.A> while if I save a temporary const mode = new Subject(Mode.A); then it infers Subject<Mode> and passes.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從連結的 TypeScript Playground 重現開始,並比較 PR #61668 引入的推論變更。追蹤 Promise.all 的直接回傳路徑,以及與之相對的暫存變數情況,然後檢查 enum 範例,作為第二個回歸問題。完成的標準是:兩個範例都如描述般推論出 tuple 和 enum 型別,且不會使現有行為發生回歸。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- typescript
- 領域
- compilers
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100