microsoft / microsoft/TypeScript

[Regression 3.9 -> 4.X] Variadic tuple type is not correctly inferred

Aperta
#42,314 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

🔎 Search Terms

variadic tuple, regression, inference

🕗 Version & Regression Information
  • This changed between versions 3.9.X and 4.X.X
⏯ Playground Link

Typescript 3.9 (works as expected)

Typescript 4.0 (does not work any more)

💻 Code
type Sink<T> = (t: number, payload: T) => void;

type Producer<T> = (t: number, sink: Sink<T>) => void;

type ExtractContent<T extends [Producer<unknown>, ...Producer<unknown>[]]> = {
    [k in keyof T]: T[k] extends Producer<infer U> ? U : never;
}

function combineWith<T extends [Producer<unknown>, ...Producer<unknown>[]], U>(
    fn: (...args: ExtractContent<T>) => U,
    ...sources: T
): Producer<U> {
    return undefined as any;
}

function of<T>(n: T): Producer<T> {
    return undefined as any;
}

const x = combineWith((x, y) => x + y, of(1), of(2));

With typescript 3.9, the arguments of the lambda passed to combineWith are correctly read as (number, number). With 4.0 everything is just unknown, even the Producer arguments later

🙁 Actual behavior

x and y (of the lambda function) are types unknown

🙂 Expected behavior

x and y (of the lambda function) are types number

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

Inizia con le riproduzioni collegate di Playground per TypeScript 3.9 e 4.0 e con le definizioni di combineWith, ExtractContent, Producer e of nell’issue. Confronta il comportamento dell’inferenza tra le versioni e conferma il completamento quando i parametri del callback e gli argomenti successivi di Producer vengono inferiti come number anziché unknown.

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
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.