microsoft / microsoft/TypeScript
A tuple containing a spread not at the trailing edge has its minimum length calculated incorrectly
未关闭
还没有人认领这个 Issue。
Bug
Domain: check: Type Inference
Help Wanted
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
Bug Report
🔎 Search Terms
- tuple
- spread
🕗 Version & Regression Information
It happens in v4.9.5, no idea about other versions.
⏯ Playground Link
💻 Code
type FN1 <T> = (...args: string[]) => T;
type FN2 <T> = ( ...args: [consumed: string, ...groups: string[], input: string, index: string] ) => T;
const fn1: FN1<number> = ( a, b ) => 0;
const fn2: FN2<number> = ( a, b ) => 0;
🙁 Actual behavior
TS complains about my fn2, with the following error:
Type '(a: string, b: string) => number' is not assignable to type 'FN2<number>'.
Types of parameters 'b' and 'groups' are incompatible.
Type '[...groups: string[], input: string, index: string]' is not assignable to type '[b: string]'.
Source has 2 element(s) but target allows only 1.(2322)
If I'm interpreting it correctly it is saying like "hey you defined two arguments, but maybe this tuple only has one item in it.
🙂 Expected behavior
If I'm interpreting the error correctly then the error is wrong because there's no scenario where that tuple has just one item in it, minimum it will always have 3.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在链接的 TypeScript Playground 中,使用 issue 中的 tuple 类型和 function 类型重现该报告。跟踪 compiler 对位于非末尾位置的 spread 进行 tuple 最小长度计算的过程。完成的标准是:示例不再报告源 tuple 可能只有一个元素,同时对于确实过短的 tuple,现有的诊断行为仍然正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100