Skip to content

Commit 9505a18

Browse files
committed
Add tests when object spread is used in destructuring
1 parent 07ce4bd commit 9505a18

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
tests/cases/compiler/unusedLocalsAndObjectSpread.ts(7,12): error TS6133: 'a' is declared but never used.
2+
tests/cases/compiler/unusedLocalsAndObjectSpread.ts(14,15): error TS6133: '_' is declared but never used.
3+
4+
5+
==== tests/cases/compiler/unusedLocalsAndObjectSpread.ts (2 errors) ====
6+
7+
declare var console: { log(a: any): void };
8+
9+
function one() {
10+
const foo = { a: 1, b: 2 };
11+
// 'a' is declared but never used
12+
const {a, ...bar} = foo;
13+
~
14+
!!! error TS6133: 'a' is declared but never used.
15+
console.log(bar);
16+
}
17+
18+
function two() {
19+
const foo = { a: 1, b: 2 };
20+
// '_' is declared but never used
21+
const {a: _, ...bar} = foo;
22+
~
23+
!!! error TS6133: '_' is declared but never used.
24+
console.log(bar);
25+
}
26+
27+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//// [unusedLocalsAndObjectSpread.ts]
2+
3+
declare var console: { log(a: any): void };
4+
5+
function one() {
6+
const foo = { a: 1, b: 2 };
7+
// 'a' is declared but never used
8+
const {a, ...bar} = foo;
9+
console.log(bar);
10+
}
11+
12+
function two() {
13+
const foo = { a: 1, b: 2 };
14+
// '_' is declared but never used
15+
const {a: _, ...bar} = foo;
16+
console.log(bar);
17+
}
18+
19+
20+
21+
//// [unusedLocalsAndObjectSpread.js]
22+
var __rest = (this && this.__rest) || function (s, e) {
23+
var t = {};
24+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
25+
t[p] = s[p];
26+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
27+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
28+
t[p[i]] = s[p[i]];
29+
return t;
30+
};
31+
function one() {
32+
var foo = { a: 1, b: 2 };
33+
// 'a' is declared but never used
34+
var a = foo.a, bar = __rest(foo, ["a"]);
35+
console.log(bar);
36+
}
37+
function two() {
38+
var foo = { a: 1, b: 2 };
39+
// '_' is declared but never used
40+
var _ = foo.a, bar = __rest(foo, ["a"]);
41+
console.log(bar);
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@noUnusedLocals:true
2+
3+
declare var console: { log(a: any): void };
4+
5+
function one() {
6+
const foo = { a: 1, b: 2 };
7+
// 'a' is declared but never used
8+
const {a, ...bar} = foo;
9+
console.log(bar);
10+
}
11+
12+
function two() {
13+
const foo = { a: 1, b: 2 };
14+
// '_' is declared but never used
15+
const {a: _, ...bar} = foo;
16+
console.log(bar);
17+
}
18+

0 commit comments

Comments
 (0)