microsoft / microsoft/TypeScript

`infer` not returning expected inner type if another inner type is used in the outer type result

Aperta
#54,213 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: Conditional Types Possible Improvement
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

Given a generic outer type with 2 or more inner types, e.g. Foo<A, B>, that does an intersection involving multiple inner types, then infer won't return a specific inner type, it will return the intersection of the desired type plus the entire outer type. This is difficult for me to explain since I don't know the correct terms for everything, so please see the example.

🔎 Search Terms

infer intersection

🕗 Version & Regression Information
  • This changed between versions 4.1.5 and 4.2.3
⏯ Playground Link

playground link

💻 Code
type Foo<T extends {}, N extends string> = T & {
  bar: number;
  asdf: N;
};

interface A {
  things: number;
}

type MyFoo = Foo<A, 'asdf'>;

type InnerFromFoo<F> = F extends Foo<infer I, string> ? I : never;

type inner = InnerFromFoo<MyFoo>;

const a: inner = {
  things: 23
};
🙁 Actual behavior

The type inner is the intersection of A and { bar: number, asdf: string }

🙂 Expected behavior

inner should just be A

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 l'esempio collegato di TypeScript Playground e con il tipo condizionale generico InnerFromFoo<F>. Confronta il tipo inner inferito con il risultato A previsto nelle versioni di TypeScript segnalate, quindi verifica che l'esempio inferisca solo il tipo interno anziché un'intersezione con il tipo esterno.

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
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.