microsoft / microsoft/TypeScript

Type inference regression on function calls not saved to variables, due to #61668

未关闭
#62,071 1 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Domain: check: Type Inference Help Wanted Possible Improvement
主要语言
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

https://www.typescriptlang.org/play/?ts=5.9.0-beta#code/PTAEGIDYEZMgOUBjAFgQwHYHMCmBnUAFxR1AEsMAzHAJxwyVMpoHsBbUAbQwFc2AjWgBpQeQjQpYAukRagAFLwG0APmInYAlJykAoACY4kAGzR1QlHg0JkWGULkIA5PvM0AuUAAVWbMnhwAHiVBGgA+AG4DI1NzS2tbe0cAZXE3Tx92fyD1SUjokzMmKyQbO1AeAIAVHgAHYxx5QjqGz24+UJFc7CkPUAA3FjJ9KKQ7MVBa0ABeb19sgDo6PBZjfsadTQXienk3GbC5rICFtGNjeU5HFzY3ERS0zV6tnYx5Spwa+pxNKKA

### 💻 Code

```ts
declare function getNum(): Promise;
declare function getStr(): Promise;
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](https://www.typescriptlang.org/play/?ts=5.9.0-beta#code/PTAEDkHkBUFEC5QHsBGBnApgJwG7baAJYEDGSAdgC5YCGONWhNVAUCQDY1oEDKArigBWGEpQA80AHygA3i1DJ02PFjSIAFOvrs+GRNACUoALzScSQgBMDAbQC6J0PYDc80GXJpqfUUizqAB0Z6SgxQAH1tXX0jGQBfFgSWDHI+AFtQAFkkSzC5BQBBRwByGmKAGjcAIRKUCsSWNk5uUB5lQhI8tzScjABCRH4hEXFs3MlXBNyOBjCAMz5yUUIKdywMGlDskgBrMUghSUCsJAC1WRsABSJyUB2MAE8kOdADwTsAfkQ3q7s4g0Q5isrjY602GG2ezauA6GCO+VAIAgMAQoGgAAtiDc5tgUp13OjmABzDCWG6gADEADYAIxUqkADm6vUQ5AwAHdWgJhKJ1GMMAA6AoGSr-EEeLygHq5RxszlDHmUPm9IUGVxIhSgAB6H1BGy2SF2YmhOFh8OlGDFLCAA), I pass `{mode: new Subject(Mode.A)}` into a function that fails because it infers `Subject` while if I save a temporary `const mode = new Subject(Mode.A);` then it infers `Subject` and passes.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 TypeScript Playground 复现开始,并比较 PR #61668 引入的推断变化。跟踪 Promise.all 的直接返回路径以及与之相对的临时变量情况,然后检查 enum 示例,作为第二个回归问题。完成的标准是:两个示例都按描述推断出 tuple 和 enum 类型,且不会使现有行为发生回归。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。