microsoft / microsoft/TypeScript
NoInfer doesn't work in string template types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
NoInfer string template
🕗 Version & Regression Information
This issue exists in every Playground-accessible version that has NoInfer.
⏯ Playground Link
💻 Code
function f<A>(a: NoInfer<A>, b: A extends string ? `rel:${A}` : never) {}
f("5", "rel:7"); // error - correct, type of A is "7"
but
function g<A>(a: A, b: A extends string ? `rel:${NoInfer<A>}` : never) {}
g("5", "rel:7"); // no error - surprising - type of A is inferred to be ("5" | "7")
🙁 Actual behavior
no type error on g() above, because the A type is being inferred via the string template in spite of the NoInfer marker.
🙂 Expected behavior
Both of the example calls should be recognized as wrong?
Additional information about the issue
Also tried
function g<A>(a: A, b: A extends string ? NoInfer<`rel:${A}`> : never) {}
function g<A>(a: A, b: NoInfer<A extends string ? `rel:${A}` : never>) {}
no luck.
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 two generic-call examples in the linked TypeScript Playground and compare how NoInfer behaves in the parameter and string-template forms. Trace the type inference behavior for NoInfer inside template literal types; done means the g("5", "rel:7") call is rejected as expected, with coverage for the shown variants.
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