-
Notifications
You must be signed in to change notification settings - Fork 12.6k
/
destructuringObjectBindingPatternAndAssignment9SiblingInitializer.types
95 lines (82 loc) · 1.96 KB
/
destructuringObjectBindingPatternAndAssignment9SiblingInitializer.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
//// [tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts] ////
=== destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts ===
// To be inferred as `number`
function f1() {
>f1 : () => void
const { a1, b1 = a1 } = { a1: 1 };
>a1 : number
>b1 : number
>a1 : number
>{ a1: 1 } : { a1: number; b1?: number; }
>a1 : number
>1 : 1
const { a2, b2 = 1 + a2 } = { a2: 1 };
>a2 : number
>b2 : number
>1 + a2 : number
>1 : 1
>a2 : number
>{ a2: 1 } : { a2: number; b2?: number; }
>a2 : number
>1 : 1
}
// To be inferred as `string`
function f2() {
>f2 : () => void
const { a1, b1 = a1 } = { a1: 'hi' };
>a1 : string
>b1 : string
>a1 : string
>{ a1: 'hi' } : { a1: string; b1?: string; }
>a1 : string
>'hi' : "hi"
const { a2, b2 = a2 + '!' } = { a2: 'hi' };
>a2 : string
>b2 : string
>a2 + '!' : string
>a2 : string
>'!' : "!"
>{ a2: 'hi' } : { a2: string; b2?: string; }
>a2 : string
>'hi' : "hi"
}
// To be inferred as `string | number`
function f3() {
>f3 : () => void
const { a1, b1 = a1 } = { a1: 'hi', b1: 1 };
>a1 : string
>b1 : string | number
>a1 : string
>{ a1: 'hi', b1: 1 } : { a1: string; b1?: number; }
>a1 : string
>'hi' : "hi"
>b1 : number
>1 : 1
const { a2, b2 = a2 + '!' } = { a2: 'hi', b2: 1 };
>a2 : string
>b2 : string | number
>a2 + '!' : string
>a2 : string
>'!' : "!"
>{ a2: 'hi', b2: 1 } : { a2: string; b2?: number; }
>a2 : string
>'hi' : "hi"
>b2 : number
>1 : 1
}
// Based on comment:
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
declare const yadda: { a?: number, b?: number } | undefined
>yadda : { a?: number; b?: number; }
>a : number
>b : number
function f4() {
>f4 : () => void
const { a, b = a } = yadda ?? {};
>a : number
>b : number
>a : number
>yadda ?? {} : { a?: number; b?: number; }
>yadda : { a?: number; b?: number; }
>{} : {}
}