Merge pull request #13100 from Microsoft/unusedLocalsInSpread
Do not report error on unused removed property from object spread when its module member
This commit is contained in:
commit
74a9924db7
4 changed files with 85 additions and 1 deletions
|
@ -16899,7 +16899,7 @@ namespace ts {
|
|||
if (!local.isReferenced && !local.exportSymbol) {
|
||||
for (const declaration of local.declarations) {
|
||||
if (!isAmbientModule(declaration)) {
|
||||
error(declaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
|
||||
errorUnusedLocal(declaration.name, local.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts(6,6): error TS6133: 'rest' is declared but never used.
|
||||
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts(9,10): error TS6133: 'foo' is declared but never used.
|
||||
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts(13,8): error TS6133: 'rest' is declared but never used.
|
||||
|
||||
|
||||
==== tests/cases/compiler/unusedLocalsAndObjectSpread2.ts (3 errors) ====
|
||||
|
||||
declare let props: any;
|
||||
const {
|
||||
children, // here!
|
||||
active: _a, // here!
|
||||
...rest,
|
||||
~~~~
|
||||
!!! error TS6133: 'rest' is declared but never used.
|
||||
} = props;
|
||||
|
||||
function foo() {
|
||||
~~~
|
||||
!!! error TS6133: 'foo' is declared but never used.
|
||||
const {
|
||||
children,
|
||||
active: _a,
|
||||
...rest,
|
||||
~~~~
|
||||
!!! error TS6133: 'rest' is declared but never used.
|
||||
} = props;
|
||||
}
|
||||
|
||||
export const asdf = 123;
|
37
tests/baselines/reference/unusedLocalsAndObjectSpread2.js
Normal file
37
tests/baselines/reference/unusedLocalsAndObjectSpread2.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
//// [unusedLocalsAndObjectSpread2.ts]
|
||||
|
||||
declare let props: any;
|
||||
const {
|
||||
children, // here!
|
||||
active: _a, // here!
|
||||
...rest,
|
||||
} = props;
|
||||
|
||||
function foo() {
|
||||
const {
|
||||
children,
|
||||
active: _a,
|
||||
...rest,
|
||||
} = props;
|
||||
}
|
||||
|
||||
export const asdf = 123;
|
||||
|
||||
//// [unusedLocalsAndObjectSpread2.js]
|
||||
"use strict";
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var children = props.children, // here!
|
||||
_a = props.active, // here!
|
||||
rest = __rest(props, ["children", "active"]);
|
||||
function foo() {
|
||||
var children = props.children, _a = props.active, rest = __rest(props, ["children", "active"]);
|
||||
}
|
||||
exports.asdf = 123;
|
18
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts
Normal file
18
tests/cases/compiler/unusedLocalsAndObjectSpread2.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
//@noUnusedLocals:true
|
||||
|
||||
declare let props: any;
|
||||
const {
|
||||
children, // here!
|
||||
active: _a, // here!
|
||||
...rest,
|
||||
} = props;
|
||||
|
||||
function foo() {
|
||||
const {
|
||||
children,
|
||||
active: _a,
|
||||
...rest,
|
||||
} = props;
|
||||
}
|
||||
|
||||
export const asdf = 123;
|
Loading…
Reference in a new issue