microsoft / microsoft/TypeScript
Generic with default type incorrectly constraint suggestions in code completion
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
When I have a function with generic constraints with a default value, IDEs' code completion only suggests the default value, despite accepting all constraint values.
🔎 Search Terms
Generic with default type
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
Generic with default type
⏯ Playground Link
Playground link with relevant code
💻 Code
type Options = 'a' | 'b' | 'c'
type Result<T extends Options> = T extends 'a' ? true : false;
declare function func<T extends Options = 'a'>(arg?: T): Result<T>
const result = func('') // Code completion only suggests 'a'
🙁 Actual behavior
IDEs' code completion only suggests the default value.
🙂 Expected behavior
IDEs' code completion should suggest all constraint values.
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
Open the linked TypeScript Playground and reproduce completion for the generic function shown in the issue. Trace the completion behavior for a constrained generic with a default type, then verify that all values from the constraint are suggested while the default remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100