TypeScript/tests/baselines/reference/typeParameterLeak.types
Anders Hejlsberg ef2c98fc35
Optimize checking involving large discriminated union types (#42556)
* No array literal subtype reduction when contextual type is present

* Accept new baselines

* Fast path in relations and filtering of pure discriminated union types

* Create maps for mixed unions, but not for small or primitive only unions

* Create many-to-many mapping with certain limits, also use in CFA

* Use constituent maps in CFA for switch statements, cleanup, add comments

* Revert change to apparent contextual type / better criteria for map eligibility

* Deduplicate array literal element types

* Accept new baselines

* Filter in false case only when discriminant property has unit type

* Only subtype reduce unions with less than 100 distinct types

* Accept new baselines

* Caching and quick discriminant checks in subtype reduction

* Accept new baselines

* Remove deduplication logic now that subtype reduction was optimized
2021-02-28 16:38:20 -08:00

51 lines
1.6 KiB
Plaintext

=== tests/cases/compiler/typeParameterLeak.ts ===
// Repro from #35655
interface Box<T> { data: T }
>data : T
type BoxTypes = Box<{ x: string }> | Box<{ y: string }>;
>BoxTypes : BoxTypes
>x : string
>y : string
type BoxFactoryFactory<TBox> = TBox extends Box<infer T> ? {
>BoxFactoryFactory : BoxFactoryFactory<TBox>
(arg: T): BoxFactory<TBox> | undefined
>arg : T
} : never;
interface BoxFactory<A> {
getBox(): A,
>getBox : () => A
}
declare const f: BoxFactoryFactory<BoxTypes>;
>f : ((arg: { x: string; }) => BoxFactory<Box<{ x: string; }>> | undefined) | ((arg: { y: string; }) => BoxFactory<Box<{ y: string; }>> | undefined)
const b = f({ x: "", y: "" })?.getBox();
>b : Box<{ x: string; }> | Box<{ y: string; }> | undefined
>f({ x: "", y: "" })?.getBox() : Box<{ x: string; }> | Box<{ y: string; }> | undefined
>f({ x: "", y: "" })?.getBox : (() => Box<{ y: string; }>) | (() => Box<{ x: string; }>) | undefined
>f({ x: "", y: "" }) : BoxFactory<Box<{ x: string; }>> | BoxFactory<Box<{ y: string; }>> | undefined
>f : ((arg: { x: string; }) => BoxFactory<Box<{ x: string; }>> | undefined) | ((arg: { y: string; }) => BoxFactory<Box<{ y: string; }>> | undefined)
>{ x: "", y: "" } : { x: string; y: string; }
>x : string
>"" : ""
>y : string
>"" : ""
>getBox : (() => Box<{ y: string; }>) | (() => Box<{ x: string; }>) | undefined
if (b) {
>b : Box<{ x: string; }> | Box<{ y: string; }> | undefined
const x = b.data;
>x : { x: string; } | { y: string; }
>b.data : { x: string; } | { y: string; }
>b : Box<{ x: string; }> | Box<{ y: string; }>
>data : { x: string; } | { y: string; }
}