microsoft / microsoft/TypeScript
Distribute property type union members to create union of object types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the assignment from the issue's TypeScript code sample in the linked Playground and compare the reported diagnostic with the expected behavior. Done means the example is accepted while preserving correct checking for incompatible tuple and object unions; no source file or test path is identified in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100