microsoft / microsoft/TypeScript
Nested Tagged Unions
Open
Nobody has claimed this yet.
In Discussion
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.5.2
Code
type A = { type: "a", a: number }
type B = { type: "b", b: number }
type X = { type: A, a: string }
type Y = { type: B, b: string }
let x: X | Y
if (x.type.type === "a") {
x.a // Type Error
}
Expected behavior:
I would expect x to have type X inside the if-statement after disambiguating the nested tagged union types.
Actual behavior:
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 with the nested tagged-union example in the issue and reproduce it against TypeScript 2.5.2. Trace the type-checker's narrowing behavior for the nested discriminant; done means the branch narrows x to X so x.a no longer errors, with regression coverage for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100