microsoft / microsoft/TypeScript
Create subtype reduction rules for assertion functions
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
inference assert
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs
⏯ Playground Link
Playground link with relevant code
💻 Code
function Test<X extends any>(params: X[]) {}
function Test2<InParams extends readonly any[]>(params: InParams) {}
function f1(a: any): number {return 1}
function f2(a: any): string {return "string"}
function f3(a: any) {return {k: 1}}
function a1(a: any): asserts a is number {}
function a2(a: any): asserts a is string {}
function a3(a: any): asserts a is {k: number} {}
const aifwe = [f1, f2, f3]
Test([f1, f2, f3])
Test([a1, a2, a3])
Test2([f1, f2, f3])
Test2([a1, a2, a3])
🙁 Actual behavior
The Test and Test2 calls are inferred as (in order):
function Test<((a: any) => number) | ((a: any) => string) | ((a: any) => { k: number; })>(params: (((a: any) => number) | ((a: any) => string) | ((a: any) => { k: number; }))[]): voidfunction Test<(a: any) => asserts a is number>(params: ((a: any) => asserts a is number)[]): voidfunction Test2<(((a: any) => number) | ((a: any) => string) | ((a: any) => { k: number; }))[]>(params: (((a: any) => number) | ((a: any) => string) | ((a: any) => { k: number; }))[]): voidfunction Test2<((a: any) => asserts a is number)[]>(params: ((a: any) => asserts a is number)[]): void
🙂 Expected behavior
For the assert calls to also be inferred as unions.
This is also irregular since with the wrong inference, I would expect the other functions to be marked as errors, since they have different type signatures.
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 collegato di TypeScript Playground e traccia l'inferenza generica per gli array di funzioni di asserzione, concentrandoti sulle regole di riduzione dei sottotipi richieste. Il lavoro è completato quando le chiamate di asserzione di Test e Test2 inferiscono unioni come le chiamate di funzioni ordinarie, con il comportamento di inferenza rilevante coperto da un test 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