microsoft / microsoft/TypeScript

Infer type isn't contextual typed by type bounds

Aperta
#44,065 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Conditional Types
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Bug Report

Infer type isn't contextual typed by type bounds

type Foo<T> = T extends string ? Record<T, number> : never;

type Foo2<T extends {a:string}>= T extends {a: infer A} ?  Record<A, number>:never; //error here, A should extends string already, but seems not
🔎 Search Terms

generic infer bounds

🕗 Version & Regression Information

4.2.3

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAYg9nAPAFQHxQLxWVCAPYCAOwBMBnKM4AJwEsiBzKAfigCUIBjOaklAGihEArgFsARhGroAXEIgA3KQG4AUKtCRYCAEwpcBYuSgBvAIYyqdRgF9UWHPkKkK5ufQBmUqAEEbLKHYuHj4fQREJKVQZIkUVIA

💻 Code
type Foo<T> = T extends string ? Record<T, number> : never;

type Foo2<T extends {a:string}>= T extends {a: infer A} ?  Record<A, number>:never; //error here, A should extends string already, but seems not

🙁 Actual behavior

throw error

🙂 Expected behavior

not throw error

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 il TypeScript Playground collegato e l’esempio ridotto Foo2 per riprodurre l’errore. L’issue non indica alcun file sorgente né alcun test; traccia come il compilatore gestisce i vincoli di tipo inferiti, quindi verifica che l’esempio accetti Record<A, number> come previsto e aggiungi la copertura di regressione.

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.