microsoft / microsoft/TypeScript
Generics in union should be inferred as `never` when possible
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
generics, inference, union, never
### 🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about union and never.
### ⏯ Playground Link
https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAZjAvDAPAFQDQD4AUAPALhjRgB8ZoAnASzAHMMYBPIk8sAVwFsAjAU0oBKJFmYAoODgDkAQymMAjMIgyo1CHGp8IMTrwEwA9IeIx1MAEQyLukAHcxY0JFh0kqEnzxQ+YACY6HP58mmB8friEpuzc-EIiMHhidDhKFKrqmtq6sQbGpuZBfiG04bZ2QA
### 💻 Code
```ts
const f = (x: T | string, y: T | number) => y
f('a', 1) satisfies number // T is "a" now
const g = (x: T | number) => x
g(1) satisfies number // T is undefined now
```
### 🙁 Actual behavior
`T` is not `never`.
### 🙂 Expected behavior
`T` should be inferred as `never`, because it can be anything.
### Additional information about the issue
This may be related to #42491.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 复现开始,并将其泛型推断行为与相关 issue #42491 进行比较。当两个示例中的 T 都被推断为 never,且 satisfies 检查产生预期结果时,工作即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100