File: typeParameterLeak.types

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
=== tests/cases/compiler/typeParameterLeak.ts ===
// Repro from #35655

interface Box<T> { data: T }
>data : T

type BoxTypes = Box<{ x: string }> | Box<{ y: string }>;
>BoxTypes : Box<{ x: string; }> | Box<{ y: string; }>
>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; }
}