Generic function does not accept argument of type with union and intersection
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- compilers
Direzione di ricerca
Inizia con il TypeScript Playground collegato e riproduci le due chiamate generiche usando le versioni 3.6.0-dev.20190723 e 3.6.0-dev.20190724. Traccia il comportamento del compilatore per i vincoli di unione e intersezione. Il lavoro è completato quando testA accetta s1 e inferisce a2 come B senza introdurre nuovi errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
🔎 Search Terms
generic function union intersection type optional property
🕗 Version & Regression Information
- This changed between versions 3.6.0-dev.20190723 and version 3.6.0-dev.20190724
⏯ Playground Link
Playground link with relevant code
💻 Code
type A = ({ a: any } | { b: any }) & { c?: any };
declare function testA<Param extends A>(param: Param & A): Param;
declare const s1: A;
const a1 = testA(s1);
/**
* Argument of type 'A' is not assignable to parameter of type '{ b: any; } & A'.
* Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & A'.
* Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & { a: any; } & { c?: any; }'.
* Property 'b' is missing in type '{ a: any; } & { c?: any; }' but required in type '{ b: any; }'.(2345)
*/
type B = ({ a: any } | { b: any }) & { c: any };
declare const s2: B;
const a2 = testA(s2); // Type of result is A but must be B
🙁 Actual behavior
The line const a1 = testA(s1); gives an error:
Argument of type 'A' is not assignable to parameter of type '{ b: any; } & A'.
Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & A'.
Type '{ a: any; } & { c?: any; }' is not assignable to type '{ b: any; } & { a: any; } & { c?: any; }'.
Property 'b' is missing in type '{ a: any; } & { c?: any; }' but required in type '{ b: any; }'.(2345)
In the line const a2 = testA(s2); the typescript compiler infers the constanta a2 has type A
🙂 Expected behavior
The variable s1 has the type A that means function testA<Param extends A>(param: Param & A): Param accepts s1. The parameter type Param is instantiated to A.
The constant a2 has the type B since the parameter s2 has the type B.
It was a normal behavior up to version 3.6.0-dev.20190723. Since then it leads to errors.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
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.
Altre issue di microsoft/TypeScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/TypeScript#64322 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Possible Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64278 · 1 commento · 1 reazione ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
microsoft/TypeScript#64118 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#63959 · 5 commenti ·
Tutte le issue di microsoft/TypeScript
Issue simili
-
optimization optimization:agents-md-curator
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
blinklabs-io/bursa#904 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 commenti ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100