microsoft / microsoft/TypeScript

Generic with default type incorrectly constraint suggestions in code completion

Aperta
#52,516 10 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: LS: Completion Lists Experience Enhancement Suggestion
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.

https://user-images.githubusercontent.com/12190482/215557275-265d803c-9e1a-431b-896a-b0b670bbfafd.mov

🔎 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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.