-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
Copy pathgenericObjectSpreadResultInSwitch.types
73 lines (58 loc) · 1.71 KB
/
genericObjectSpreadResultInSwitch.types
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
=== tests/cases/compiler/genericObjectSpreadResultInSwitch.ts ===
type Params = {
>Params : Params
foo: string;
>foo : string
} & ({ tag: 'a'; type: number } | { tag: 'b'; type: string });
>tag : "a"
>type : number
>tag : "b"
>type : string
const getType = <P extends Params>(params: P) => {
>getType : <P extends Params>(params: P) => Omit<P, "foo">
><P extends Params>(params: P) => { const { // Omit foo, ...rest } = params; return rest;} : <P extends Params>(params: P) => Omit<P, "foo">
>params : P
const {
// Omit
foo,
>foo : string
...rest
>rest : Omit<P, "foo">
} = params;
>params : Params
return rest;
>rest : Omit<P, "foo">
};
declare const params: Params;
>params : Params
switch (params.tag) {
>params.tag : "a" | "b"
>params : Params
>tag : "a" | "b"
case 'a': {
>'a' : "a"
// TS 4.2: number
// TS 4.3: string | number
const result = getType(params).type;
>result : number
>getType(params).type : number
>getType(params) : Omit<{ foo: string; } & { tag: "a"; type: number; }, "foo">
>getType : <P extends Params>(params: P) => Omit<P, "foo">
>params : { foo: string; } & { tag: "a"; type: number; }
>type : number
break;
}
case 'b': {
>'b' : "b"
// TS 4.2: string
// TS 4.3: string | number
const result = getType(params).type;
>result : string
>getType(params).type : string
>getType(params) : Omit<{ foo: string; } & { tag: "b"; type: string; }, "foo">
>getType : <P extends Params>(params: P) => Omit<P, "foo">
>params : { foo: string; } & { tag: "b"; type: string; }
>type : string
break;
}
}