microsoft / microsoft/TypeScript
Allow inferring return type within a type guard in conditional types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
typeguard conditional infer
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about (bug reporting)
⏯ Playground Link
Playground link with relevant code
💻 Code
This is simplified pretty heavily:
type InferredTypeGuard<TypeGuard> =
TypeGuard extends ((node: infer Input) => node is infer Output)
? (node: Input) => node is Output
: never;
🙁 Actual behavior
Error on infer Output:
A type predicate's type must be assignable to its parameter's type.
Type 'Output' is not assignable to type 'Input'.
'Input' could be instantiated with an arbitrary type which could be unrelated to 'Output'.(2677)
🙂 Expected behavior
TypeScript should allow a conditional type to infer the Output type within the type guard function's return type.
There's no other syntax I can find to do so, and I would have thought this would be the cleanest syntax. Not sure if bug report or feature request...
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 l'esempio TypeScript Playground collegato e il tipo condizionale semplificato che usa infer Input e infer Output. Traccia il controllo di assegnabilità del predicato di tipo che segnala l'errore 2677 e determina come dovrebbe interagire con esso l'inferenza dei tipi condizionali. Il lavoro è completato quando l'esempio viene verificato con i tipi di input e output inferiti attesi, con una copertura di regressione per questo comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100