microsoft / microsoft/TypeScript
Generics; ReturnType<Foo> != ReturnType<typeof foo>
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: Version 2.9.0-dev.20180516
Search Terms: generic function returntype
I couldn't think of a good title for this,
Code
type Delegate<T> = () => T;
function executeGeneric<
X,
DelegateT extends Delegate<X>
>(delegate: DelegateT): ReturnType<DelegateT> {
//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
const x: ReturnType<typeof delegate> = delegate();
//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
const y: ReturnType<DelegateT> = delegate();
//Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
return delegate();
}
Expected behavior:
Return successfully.
Intuitively, to me,
delegateis of typeDelegateT.ReturnType<DelegateT>andReturnType<typeof delegate>should be the same
However,
Actual behavior:
Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
Playground Link: Here
Related Issues:
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 dalla riproduzione collegata di TypeScript Playground e confronta i tipi di ReturnType e ReturnType nella funzione generica. Determina se gli errori di assegnazione segnalati debbano essere eliminati mantenendo la relazione generica indicata, quindi verifica che la riproduzione non segnali più tali errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100