microsoft / microsoft/TypeScript

bug(lib): Explicitly stating wrong return type of `Promise.then` without arguments results in no error

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

还没有人认领这个 Issue。

Needs Proposal
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 Search Terms

- silenced Promise resolution type mismatch
- Promise generic explicit no error
- no error when Promise type is specified explicitly
- generic inside optional argument

### 🕗 Version & Regression Information

TS v3.3.3 correctly detects the error, which is the earliest Playground version. All other Playground versions silence the error.

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260312#code/MYewdgzgLgBFCm0BcMAKAnEBbAlheAPNOjmAOYB8MAvGprvgHTqIgA2AbvABQCMAlIygALeGG78A3EA

### 💻 Code

```ts
const test: Promise = Promise.resolve(1).then();
```

### 🙁 Actual behavior

No TypeScript errors.

### 🙂 Expected behavior

I expected a similar error to what TS v3.3.3 yields:
> Type `Promise` is not assignable to type `Promise`. Type `number` is not assignable to type `string`.

### Additional information about the issue

_No response_

贡献指南

打开贡献指南

从这里开始

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

调研方向

在链接的 TypeScript Playground 中重现报告的示例,将当前行为与 issue 中描述的 TypeScript 3.3.3 结果进行比较。跟踪不带参数调用的 Promise.then 的类型检查路径;完成标准是显式的 Promise 赋值报告与 Promise 不匹配。

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

评估

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

把新 issue 发到你的邮箱

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