Skip to content

Commit dfee3de

Browse files
committed
Add test case for #8229
1 parent 906ce18 commit dfee3de

6 files changed

+115
-9
lines changed

tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,18): error TS
1515
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,5): error TS1182: A destructuring declaration must have an initializer.
1616
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,13): error TS7008: Member 'b3' implicitly has an 'any' type.
1717
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,25): error TS7008: Member 'b3' implicitly has an 'any' type.
18-
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7031: Binding element 'a1' implicitly has an 'any' type.
19-
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b1' implicitly has an 'any' type.
18+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7031: Binding element 'a4' implicitly has an 'any' type.
19+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b4' implicitly has an 'any' type.
20+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,46): error TS7005: Variable 'c4' implicitly has an 'any' type.
21+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS7005: Variable 'd4' implicitly has an 'any' type.
2022

2123

22-
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (19 errors) ====
24+
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (21 errors) ====
2325
var [a], {b}, c, d; // error
2426
~~~
2527
!!! error TS1182: A destructuring declaration must have an initializer.
@@ -62,8 +64,12 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS
6264
~~
6365
!!! error TS7008: Member 'b3' implicitly has an 'any' type.
6466

65-
var [a1] = [undefined], {b1} = { b1: null }, c1 = undefined, d1 = null; // error
67+
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
6668
~~
67-
!!! error TS7031: Binding element 'a1' implicitly has an 'any' type.
69+
!!! error TS7031: Binding element 'a4' implicitly has an 'any' type.
6870
~~
69-
!!! error TS7031: Binding element 'b1' implicitly has an 'any' type.
71+
!!! error TS7031: Binding element 'b4' implicitly has an 'any' type.
72+
~~
73+
!!! error TS7005: Variable 'c4' implicitly has an 'any' type.
74+
~~
75+
!!! error TS7005: Variable 'd4' implicitly has an 'any' type.

tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
77

88
var {b3}: { b3 }, c3: { b3 }; // error in type instead
99

10-
var [a1] = [undefined], {b1} = { b1: null }, c1 = undefined, d1 = null; // error
10+
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
1111

1212
//// [noImplicitAnyDestructuringVarDeclaration.js]
1313
var a = (void 0)[0], b = (void 0).b, c, d; // error
1414
var _a = (void 0)[0], a1 = _a === void 0 ? undefined : _a, _b = (void 0).b1, b1 = _b === void 0 ? null : _b, c1 = undefined, d1 = null; // error
1515
var a2 = (void 0)[0], b2 = (void 0).b2, c2, d2;
1616
var b3 = (void 0).b3, c3; // error in type instead
17-
var a1 = [undefined][0], b1 = { b1: null }.b1, c1 = undefined, d1 = null; // error
17+
var a4 = [undefined][0], b4 = { b4: null }.b4, c4 = undefined, d4 = null; // error
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(1,6): error TS7031: Binding element 'a' implicitly has an 'any' type.
2+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(1,9): error TS7031: Binding element 'b' implicitly has an 'any' type.
3+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(1,12): error TS7031: Binding element 'c' implicitly has an 'any' type.
4+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(3,6): error TS7031: Binding element 'a2' implicitly has an 'any' type.
5+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(3,22): error TS7031: Binding element 'b2' implicitly has an 'any' type.
6+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(3,38): error TS7031: Binding element 'c2' implicitly has an 'any' type.
7+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(5,6): error TS7031: Binding element 'a4' implicitly has an 'any' type.
8+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(5,31): error TS7031: Binding element 'b4' implicitly has an 'any' type.
9+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(7,6): error TS7031: Binding element 'x' implicitly has an 'any' type.
10+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(7,9): error TS7031: Binding element 'y' implicitly has an 'any' type.
11+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(7,12): error TS7031: Binding element 'z' implicitly has an 'any' type.
12+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(9,6): error TS7031: Binding element 'x2' implicitly has an 'any' type.
13+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(9,22): error TS7031: Binding element 'y2' implicitly has an 'any' type.
14+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(9,38): error TS7031: Binding element 'z2' implicitly has an 'any' type.
15+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(11,6): error TS7031: Binding element 'x4' implicitly has an 'any' type.
16+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts(11,37): error TS7031: Binding element 'y4' implicitly has an 'any' type.
17+
18+
19+
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration2.ts (16 errors) ====
20+
let [a, b, c] = [1, 2, 3]; // no error
21+
~
22+
!!! error TS7031: Binding element 'a' implicitly has an 'any' type.
23+
~
24+
!!! error TS7031: Binding element 'b' implicitly has an 'any' type.
25+
~
26+
!!! error TS7031: Binding element 'c' implicitly has an 'any' type.
27+
let [a1 = 10, b1 = 10, c1 = 10] = [1, 2, 3]; // no error
28+
let [a2 = undefined, b2 = undefined, c2 = undefined] = [1, 2, 3]; // no error
29+
~~
30+
!!! error TS7031: Binding element 'a2' implicitly has an 'any' type.
31+
~~
32+
!!! error TS7031: Binding element 'b2' implicitly has an 'any' type.
33+
~~
34+
!!! error TS7031: Binding element 'c2' implicitly has an 'any' type.
35+
let [a3 = <any>undefined, b3 = <any>null, c3 = <any>undefined] = [1, 2, 3]; // no error
36+
let [a4] = [<any>undefined], [b4] = [<any>null], c4 = <any>undefined, d4 = <any>null; // no error
37+
~~
38+
!!! error TS7031: Binding element 'a4' implicitly has an 'any' type.
39+
~~
40+
!!! error TS7031: Binding element 'b4' implicitly has an 'any' type.
41+
42+
let {x, y, z} = { x: 1, y: 2, z: 3 }; // no error
43+
~
44+
!!! error TS7031: Binding element 'x' implicitly has an 'any' type.
45+
~
46+
!!! error TS7031: Binding element 'y' implicitly has an 'any' type.
47+
~
48+
!!! error TS7031: Binding element 'z' implicitly has an 'any' type.
49+
let {x1 = 10, y1 = 10, z1 = 10} = { x1: 1, y1: 2, z1: 3 }; // no error
50+
let {x2 = undefined, y2 = undefined, z2 = undefined} = { x2: 1, y2: 2, z2: 3 }; // no error
51+
~~
52+
!!! error TS7031: Binding element 'x2' implicitly has an 'any' type.
53+
~~
54+
!!! error TS7031: Binding element 'y2' implicitly has an 'any' type.
55+
~~
56+
!!! error TS7031: Binding element 'z2' implicitly has an 'any' type.
57+
let {x3 = <any>undefined, y3 = <any>null, z3 = <any>undefined} = { x3: 1, y3: 2, z3: 3 }; // no error
58+
let {x4} = { x4: <any>undefined }, {y4} = { y4: <any>null }; // no error
59+
~~
60+
!!! error TS7031: Binding element 'x4' implicitly has an 'any' type.
61+
~~
62+
!!! error TS7031: Binding element 'y4' implicitly has an 'any' type.
63+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [noImplicitAnyDestructuringVarDeclaration2.ts]
2+
let [a, b, c] = [1, 2, 3]; // no error
3+
let [a1 = 10, b1 = 10, c1 = 10] = [1, 2, 3]; // no error
4+
let [a2 = undefined, b2 = undefined, c2 = undefined] = [1, 2, 3]; // no error
5+
let [a3 = <any>undefined, b3 = <any>null, c3 = <any>undefined] = [1, 2, 3]; // no error
6+
let [a4] = [<any>undefined], [b4] = [<any>null], c4 = <any>undefined, d4 = <any>null; // no error
7+
8+
let {x, y, z} = { x: 1, y: 2, z: 3 }; // no error
9+
let {x1 = 10, y1 = 10, z1 = 10} = { x1: 1, y1: 2, z1: 3 }; // no error
10+
let {x2 = undefined, y2 = undefined, z2 = undefined} = { x2: 1, y2: 2, z2: 3 }; // no error
11+
let {x3 = <any>undefined, y3 = <any>null, z3 = <any>undefined} = { x3: 1, y3: 2, z3: 3 }; // no error
12+
let {x4} = { x4: <any>undefined }, {y4} = { y4: <any>null }; // no error
13+
14+
15+
//// [noImplicitAnyDestructuringVarDeclaration2.js]
16+
var _a = [1, 2, 3], a = _a[0], b = _a[1], c = _a[2]; // no error
17+
var _b = [1, 2, 3], _c = _b[0], a1 = _c === void 0 ? 10 : _c, _d = _b[1], b1 = _d === void 0 ? 10 : _d, _e = _b[2], c1 = _e === void 0 ? 10 : _e; // no error
18+
var _f = [1, 2, 3], _g = _f[0], a2 = _g === void 0 ? undefined : _g, _h = _f[1], b2 = _h === void 0 ? undefined : _h, _j = _f[2], c2 = _j === void 0 ? undefined : _j; // no error
19+
var _k = [1, 2, 3], _l = _k[0], a3 = _l === void 0 ? undefined : _l, _m = _k[1], b3 = _m === void 0 ? null : _m, _o = _k[2], c3 = _o === void 0 ? undefined : _o; // no error
20+
var a4 = [undefined][0], b4 = [null][0], c4 = undefined, d4 = null; // no error
21+
var _p = { x: 1, y: 2, z: 3 }, x = _p.x, y = _p.y, z = _p.z; // no error
22+
var _q = { x1: 1, y1: 2, z1: 3 }, _r = _q.x1, x1 = _r === void 0 ? 10 : _r, _s = _q.y1, y1 = _s === void 0 ? 10 : _s, _t = _q.z1, z1 = _t === void 0 ? 10 : _t; // no error
23+
var _u = { x2: 1, y2: 2, z2: 3 }, _v = _u.x2, x2 = _v === void 0 ? undefined : _v, _w = _u.y2, y2 = _w === void 0 ? undefined : _w, _x = _u.z2, z2 = _x === void 0 ? undefined : _x; // no error
24+
var _y = { x3: 1, y3: 2, z3: 3 }, _z = _y.x3, x3 = _z === void 0 ? undefined : _z, _0 = _y.y3, y3 = _0 === void 0 ? null : _0, _1 = _y.z3, z3 = _1 === void 0 ? undefined : _1; // no error
25+
var x4 = { x4: undefined }.x4, y4 = { y4: null }.y4; // no error

tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
77

88
var {b3}: { b3 }, c3: { b3 }; // error in type instead
99

10-
var [a1] = [undefined], {b1} = { b1: null }, c1 = undefined, d1 = null; // error
10+
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @noimplicitany: true
2+
let [a, b, c] = [1, 2, 3]; // no error
3+
let [a1 = 10, b1 = 10, c1 = 10] = [1, 2, 3]; // no error
4+
let [a2 = undefined, b2 = undefined, c2 = undefined] = [1, 2, 3]; // no error
5+
let [a3 = <any>undefined, b3 = <any>null, c3 = <any>undefined] = [1, 2, 3]; // no error
6+
let [a4] = [<any>undefined], [b4] = [<any>null], c4 = <any>undefined, d4 = <any>null; // no error
7+
8+
let {x, y, z} = { x: 1, y: 2, z: 3 }; // no error
9+
let {x1 = 10, y1 = 10, z1 = 10} = { x1: 1, y1: 2, z1: 3 }; // no error
10+
let {x2 = undefined, y2 = undefined, z2 = undefined} = { x2: 1, y2: 2, z2: 3 }; // no error
11+
let {x3 = <any>undefined, y3 = <any>null, z3 = <any>undefined} = { x3: 1, y3: 2, z3: 3 }; // no error
12+
let {x4} = { x4: <any>undefined }, {y4} = { y4: <any>null }; // no error

0 commit comments

Comments
 (0)