-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
Copy patharrayDestructuringInSwitch1.types
105 lines (96 loc) · 5.07 KB
/
arrayDestructuringInSwitch1.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//// [tests/cases/compiler/arrayDestructuringInSwitch1.ts] ////
=== arrayDestructuringInSwitch1.ts ===
export type Expression = BooleanLogicExpression | 'true' | 'false';
>Expression : Expression
> : ^^^^^^^^^^
export type BooleanLogicExpression = ['and', ...Expression[]] | ['not', Expression];
>BooleanLogicExpression : BooleanLogicExpression
> : ^^^^^^^^^^^^^^^^^^^^^^
export function evaluate(expression: Expression): boolean {
>evaluate : (expression: Expression) => boolean
> : ^ ^^ ^^^^^
>expression : Expression
> : ^^^^^^^^^^
if (Array.isArray(expression)) {
>Array.isArray(expression) : boolean
> : ^^^^^^^
>Array.isArray : (arg: any) => arg is any[]
> : ^ ^^ ^^^^^
>Array : ArrayConstructor
> : ^^^^^^^^^^^^^^^^
>isArray : (arg: any) => arg is any[]
> : ^ ^^ ^^^^^
>expression : Expression
> : ^^^^^^^^^^
const [operator, ...operands] = expression;
>operator : "and" | "not"
> : ^^^^^^^^^^^^^
>operands : Expression[] | [Expression]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>expression : BooleanLogicExpression
> : ^^^^^^^^^^^^^^^^^^^^^^
switch (operator) {
>operator : "and" | "not"
> : ^^^^^^^^^^^^^
case 'and': {
>'and' : "and"
> : ^^^^^
return operands.every((child) => evaluate(child));
>operands.every((child) => evaluate(child)) : boolean
> : ^^^^^^^
>operands.every : { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; } | { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; }
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^ ^ ^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^ ^ ^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^ ^^^
>operands : Expression[] | [Expression]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>every : { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; } | { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; }
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^ ^ ^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^ ^ ^^^ ^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^ ^^^
>(child) => evaluate(child) : (child: Expression) => boolean
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^
>child : Expression
> : ^^^^^^^^^^
>evaluate(child) : boolean
> : ^^^^^^^
>evaluate : (expression: Expression) => boolean
> : ^ ^^ ^^^^^
>child : Expression
> : ^^^^^^^^^^
}
case 'not': {
>'not' : "not"
> : ^^^^^
return !evaluate(operands[0]);
>!evaluate(operands[0]) : boolean
> : ^^^^^^^
>evaluate(operands[0]) : boolean
> : ^^^^^^^
>evaluate : (expression: Expression) => boolean
> : ^ ^^ ^^^^^
>operands[0] : Expression
> : ^^^^^^^^^^
>operands : Expression[] | [Expression]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>0 : 0
> : ^
}
default: {
throw new Error(`${operator} is not a supported operator`);
>new Error(`${operator} is not a supported operator`) : Error
> : ^^^^^
>Error : ErrorConstructor
> : ^^^^^^^^^^^^^^^^
>`${operator} is not a supported operator` : string
> : ^^^^^^
>operator : never
> : ^^^^^
}
}
} else {
return expression === 'true';
>expression === 'true' : boolean
> : ^^^^^^^
>expression : "false" | "true"
> : ^^^^^^^^^^^^^^^^
>'true' : "true"
> : ^^^^^^
}
}