microsoft / microsoft/TypeScript
Inconsistent type inference on overloaded function types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
type inference of overloaded functions
🕗 Version & Regression Information
The behaviour seemed to change between 4.0.5 and 4.1.5, but it was incorrect nonetheless.
⏯ Playground Link
💻 Code
type Callback<R> = (result: R) => void;
type Options = { context: any };
export type AsyncFunction<A extends unknown[], O extends Options, R> = {
// Swap these two lines to see the fun
(...args: [...A, Callback<R>]): void;
(...args: [...A, O, Callback<R>]): void;
};
function promisify<A extends unknown[], O extends Options, R>(f: AsyncFunction<A, O, R>) {}
function f1(n: number, c: Callback<number>): void;
function f1(n: number, o: Options, c: Callback<number>): void;
function f1(...args: any[]) {}
type AsyncOrNot<F> = F extends AsyncFunction<infer _A, infer _O, infer _R> ? true : false;
promisify(f1);
type T1 = AsyncOrNot<typeof f1>;
const t1: T1 = true;
🙁 Actual behavior
In version 4.0.5, either the inference in the function call or the inference in the conditional type succeeds, depending on the order in which the overloads are declared.
In all later versions up to and including 5.4.0 beta, the inference in the conditional type always fails.
🙂 Expected behavior
Type inference for the same type against the same generic type to always succeed or always fail, whether it is done for a generic function call or for evaluating the extends clause in a conditional type.
Additional information about the issue
No response
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 la riproduzione fornita in TypeScript Playground e confronta l'inferenza delle chiamate a funzioni generiche con l'inferenza dei tipi condizionali in TypeScript 4.0.5 e nelle versioni correnti. Traccia il percorso del controllo dei tipi per i tipi di funzione sovraccarichi, quindi verifica che entrambi i contesti abbiano esito positivo o falliscano in modo coerente, indipendentemente dall'ordine degli overload.
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