microsoft / microsoft/TypeScript
`+=` on `string | undefined` should narrow its operand to `string`
Open
Nobody has claimed this yet.
Bug
Domain: check: Control Flow
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.6.1
Code
let a: string | undefined;
a = a + "a";
a; // string
let b: string | undefined;
b += "a";
b; // should be string, but is still string | undefined
Expected behavior:
Both notations should be equivalend
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 example with TypeScript 2.6.1, comparing a = a + "a" with b += "a". Trace the type-checking path for compound assignment and add a regression test showing that b is narrowed to string after +=; done when both forms produce equivalent types without regressions.
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