microsoft / microsoft/TypeScript
Distribute property type union members to create union of object types
未关闭
还没有人认领这个 Issue。
Bug
Domain: check: Type Inference
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: v3.9.0-dev.20200222
Search Terms: union type object property
Code
type Test =
| { b: [false, "a"] }
| { b: [true, "b"] }
declare const b2: boolean;
const a: Test = { b: b2 ? [b2, "b"] : [b2, "a"] }
Expected behavior:
No error. I'm not exactly sure if this is a bug or feature request but, essentially, it'd be nice if TS could recognize that: { b: [true, "b"] | [false, "a"]; } is identical to { b: [true, "b"] } | { b: [false, "a"]; }
Actual behavior:
Type '{ b: [true, "b"] | [false, "a"]; }' is not assignable to type 'Test'.
Type '{ b: [true, "b"] | [false, "a"]; }' is not assignable to type '{ b: [true, "b"]; }'.
Types of property 'b' are incompatible.
Type '[true, "b"] | [false, "a"]' is not assignable to type '[true, "b"]'.
Type '[false, "a"]' is not assignable to type '[true, "b"]'.
Type 'false' is not assignable to type 'true'.
Playground Link: Playground Link
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,在链接的 Playground 中重现 issue 的 TypeScript 代码示例中的赋值,并将报告的诊断与预期行为进行比较。完成的标准是示例被接受,同时保留对不兼容的元组和对象联合类型的正确检查;issue 中未指定源文件或测试路径。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100