microsoft / microsoft/TypeScript
unknown types should not able to concat with strings
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.3.0
Code
declare const a: unknown;
const b = a + 123;
const c = a + '123';
const d = `${a}123`;
Expected behavior:
All the declarations of variables b c d should have errors.
Actual behavior:
Only declaration of variable b have error.
Although we won't get runtime errors in this case, it may cause unpredictable result, e.g. "[[Object]]123", which is unexpected, so I think ts should not allow unknown types to concat with strings.
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 TypeScript Playground reproduction and compare the diagnostics for b, c, and d when a is typed as unknown. Trace the type-checking behavior for arithmetic, string concatenation, and template expressions. Done means the behavior matches the stated expected errors and the relevant checks are covered.
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