microsoft / microsoft/TypeScript
Generic with default type incorrectly constraint suggestions in code completion
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Apri il TypeScript Playground collegato e riproduci il completamento per la funzione generica mostrata nell’issue. Traccia il comportamento del completamento per un generico vincolato con un tipo predefinito, quindi verifica che vengano suggeriti tutti i valori del vincolo mentre il valore predefinito rimane valido.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100