microsoft / microsoft/TypeScript

`silentNeverType` leak in contextual parameter types coming from anonymous non-aliased object type instantiations

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

还没有人认领这个 Issue。

Bug Domain: check: Type Inference Help Wanted
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 Search Terms

silent never type return type inference alias propagating anonymous object

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250827#code/JYOwLgpgTgZghgYwgAgAoB4AqA+ZBvAKGWTAAsIQAuZACgHsQYBXAGxmBZYgBNqaA3OCyYRqmAJTIAvLiYgA1iDoB3EJJnI5ilSADcBAL4ECoSLEQpUAYQYBnMFCYIwdKPiLIQEZcizYaEAAeEAhMLlB8UBC2dCz8orSCwgkS0rj8dMDc6umZ2dQYOPpGBNwhLHBRyIJuqAU2IPaOzq76peWVKMwgzsAMyDB0dACMfjSBfDlo6HjIZfCsYGLIBtjiYm0IdmDIUbaLw9IDQ8M0NFOExFFgTFAgnt5oZ3ux8RceV9GvEPrExAD0-2QAD0APweAziYpQ4xgACeAAcUAB1YBkAAiEAWLDAfiOs3mcEWywMbTKCAqVW6vX6gzoACYxhNaFMMKiMViiTi-GsNsYto0dntFvSjnT6Wd3p8bncHj5UM8vnEIFK-i9lb8-oCQeDiJDoWSOlS5DT7nSAMxMyZpaYAbUwAF1echMJttrtootzWKhubJTbLh6ZfcvPLFTFlarPhH4pqAUCwRCYfrjOTKV0TWA+mahgAWK0sm0YAmc4n4ZAIqB0BEklbO13893CnG5n10XP+jSB663EOPBU0dVvAMfD0xn6j7WJvXJmHtCmdAaZ7PHOgAVgL5yLMzmpZx1HtDrr6xdbsFY8Wa7ba87uG7EGDcqeg6Vw67o6HE7+yCnupWs90IA

### 💻 Code

```ts
interface P {
then: (onfulfilled: (value: T) => unknown) => unknown;
}

interface PConstructor {
new (executor: (resolve: (value: T) => void) => void): P;
}

declare var P: PConstructor;

declare function foo1(x: () => P<{ default: T }>): T;

const result1 = foo1(() => {
return new P((resolve) => {
resolve;
});
});

type WithDefault = { default: T };

declare function foo2(x: () => P>): T;

const result2 = foo2(() => {
return new P((resolve) => {
resolve;
});
});

declare function foo3(x: () => P<[T]>): T;

const result3 = foo3(() => {
return new P((resolve) => {
resolve;
});
});

declare function foo4(x: () => P<{ default: { prop: T } }>): T;

const result4 = foo4(() => {
return new P((resolve) => {
resolve;
});
});

declare function foo5(x: () => P<{ default: [T] }>): T;

const result5 = foo5(() => {
return new P((resolve) => {
resolve;
});
});
```

### 🙁 Actual behavior

Only `foo2` and `foo3` have errors and we can see that their inner `resolve`s reference `never`

### 🙂 Expected behavior

All of those should consistently error and `resolve` should be typed as `(value: unknown) => void`. Specifically, `foo1` and `foo2` are the almost the same signatures but `foo2` is using a type alias in its declaration which changes the inference behavior. This is strong indication of the bug here

### Additional information about the issue

_No response_

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先复现 Playground 示例,并比较 foo1 到 foo5 中的上下文参数推断,尤其是匿名对象实例化与别名类型 WithDefault 之间的差异。跟踪产生内部 resolve 类型的类型推断路径;当五个案例都一致报告错误,并且类型解析报告为接受 unknown 时,即完成。

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

评估

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

把新 issue 发到你的邮箱

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