microsoft / microsoft/TypeScript
Incorrectly typed argument variant
未关闭
还没有人认领这个 Issue。
Bug
Domain: check: Type Inference
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 3.8.3
Search Terms:
Parameters, Array, Overloading, Type inference
Code
type VariantA = [(err: Error, data: string) => any]
type VariantB = [(data: string) => any, (err: Error) => any]
type Args = VariantA | VariantB
function fn (...rest: Args): void { /* do something */ }
fn((err, data) => {
err.stack // Correct: Typed as Error
data.charAt(0) // Correct: Typed as string
})
fn((data) => {
data // --> Error: Mistyped as any, should be string <--
}, (err) => {
err.stack // Correct: Typed as Error
})
Expected behavior:
If two functions are passed in (VariantB), the first paramter should be typed as data: string.
Actual behavior:
If two functions are passed in, the first function's parameter is typed as any.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中最小的 TypeScript 复现开始,比较一个 callback 和两个 callback 调用时的上下文类型。跟踪 union rest parameter 的类型推断和 overload 处理,然后验证第一个 callback 参数被推断为 string,同时不会导致 Error 和 data 的类型声明发生回归。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100