Skip to content

Commit 307a9b6

Browse files
committed
Add tests
1 parent c1ab2b0 commit 307a9b6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @strict: true
2+
3+
function f1(obj: { a?: string }) {
4+
if (obj.a) {
5+
obj = {};
6+
let a1 = obj["a"]; // string | undefined
7+
let a2 = obj.a; // string | undefined
8+
}
9+
}
10+
11+
function f2(obj: [number, string] | null[]) {
12+
let a0 = obj[0]; // number | null
13+
let a1 = obj[1]; // string | null
14+
let [b0, b1] = obj;
15+
([a0, a1] = obj);
16+
if (obj[0] && obj[1]) {
17+
let c0 = obj[0]; // number
18+
let c1 = obj[1]; // string
19+
let [d0, d1] = obj;
20+
([c0, c1] = obj);
21+
}
22+
}
23+
24+
function f3(obj: { a?: number, b?: string }) {
25+
if (obj.a && obj.b) {
26+
let { a, b } = obj; // number, string
27+
({ a, b } = obj);
28+
}
29+
}
30+
31+
function f4() {
32+
let x: boolean;
33+
({ x } = 0); // Error
34+
({ ["x"]: x } = 0); // Error
35+
({ ["x" + ""]: x } = 0); // Errpr
36+
}

0 commit comments

Comments
 (0)