microsoft / microsoft/TypeScript
Type widening for T or Promise<T>
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
🔎 Search Terms
Type widening, promise, generic type widening.
🕗 Version & Regression Information
This is the behavior in every version I tried.
⏯ Playground Link
💻 Code
type Cb3 = <Res extends string | Promise<string>>(cb: () => Res) => Res
const c: Cb3 = {} as any;
// this don't widen the type, type of t31 is "1"
const t31 = c(() => {
return '1';
});
// but here is the problem, type of t32 is Promise<string>
const t32 = c(async () => {
return '1';
});
🙁 Actual behavior
Type of t32 is Promise<string>
🙂 Expected behavior
Type of t32 is Promise<"1">, by analogy with type of t31
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
Inizia con il TypeScript Playground collegato e confronta l’inferenza delle callback generiche negli esempi sincrono e asincrono. Traccia il punto in cui il caso Promise perde il tipo letterale; il lavoro è completato quando la chiamata asincrona viene inferita come Promise<"1"> mentre il risultato sincrono rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100