microsoft / microsoft/TypeScript
A trivial generic interface extending a generic type handles assignability differently than the base type
未关闭
还没有人认领这个 Issue。
Needs Investigation
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 4.0.5, 4.1.0-beta, 4.1.0-dev.20201102
Search Terms: generic interface assignability
Code
type Assert<T, U extends T> = U;
type A = { value: 5, a: true };
type B = { value: 5, b: true };
interface Box<T> {
value: T;
}
type _Rebox<T extends Box<any>> = Box<T["value"]>;
namespace Test0 {
type Rebox<T extends Box<any>> = _Rebox<T>;
export type Assertions = [
Assert<Box<5>, Rebox<A>>, // Correctly passes
Assert<Rebox<A>, Box<5>>, // Correctly passes
Assert<Box<5>, Rebox<B>>, // Correctly passes
Assert<Rebox<B>, Box<5>>, // Correctly passes
Assert<Rebox<A>, Rebox<B>>, // Correctly passes
];
}
namespace Test1 {
interface Rebox<T extends Box<any>> extends _Rebox<T> {};
export type Assertions = [
Assert<Box<5>, Rebox<A>>, // Correctly passes
Assert<Rebox<A>, Box<5>>, // Correctly passes
Assert<Box<5>, Rebox<B>>, // Correctly passes
Assert<Rebox<B>, Box<5>>, // Correctly passes
Assert<Rebox<A>, Rebox<B>>, // Incorrectly fails
];
}
Expected behavior: Test0.Assertions and Test1.Assertions should both resolve with no errors.
Actual behavior: When Rebox is an interface (in Test1), Rebox<B> is not assignable to Rebox<A>.
Related Issues: N/A
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的 TypeScript 重现开始,比较 Test0 和 Test1 中类型别名形式与接口形式的可赋值性结果。跟踪编译器对泛型接口和可赋值性的行为,然后添加一个回归测试,证明 Rebox 可赋值给 Rebox,并且两组断言都能在没有错误的情况下解析。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100