microsoft / microsoft/TypeScript
`${number}` template literal type does not allow "NaN" or "Infinity"
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
NaN Infinity template literal types
🕗 Version & Regression Information
4.3.0-dev.20210226
⏯ Playground Link
Playground link with relevant code
💻 Code
const a: number = NaN //no error
const b: `${number}` = 'NaN' //Type '"NaN"' is not assignable to type '`${number}`'.
const c: number = Infinity //no error
const d: `${number}` = 'Infinity' //Type '"Infinity"' is not assignable to type '`${number}`'
🙁 Actual behavior
compile errors
🙂 Expected behavior
the strings "NaN" and "Infinity" should be valid `${number}`s because NaN and Infinity are valid numbers
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 linked TypeScript Playground and the ${number} examples in the issue to reproduce the errors for NaN and Infinity. Trace the compiler's template literal type handling, then add or update the relevant compiler tests so both strings are accepted while existing ${number} behavior remains correct.
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
- 42/100