Skip to content

Commit c6ccf36

Browse files
mightyiamJamesHenry
authored andcommitted
Fix: Destructured param type annotation not marked used (fixes typescript-eslint#82) (typescript-eslint#84)
1 parent 46776aa commit c6ccf36

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: packages/eslint-plugin-typescript/lib/rules/no-unused-vars.js

+15
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ module.exports = {
9292

9393
break;
9494
}
95+
case "TSTypeLiteral": {
96+
annotation.members.forEach(member => {
97+
if (member.typeAnnotation) {
98+
markTypeAnnotationAsUsed(member.typeAnnotation);
99+
}
100+
});
101+
102+
break;
103+
}
95104
case "TSUnionType":
96105
case "TSIntersectionType":
97106
annotation.types.forEach(type => {
@@ -257,6 +266,12 @@ module.exports = {
257266
ClassDeclaration: markClassOptionsAsUsed,
258267
ClassExpression: markClassOptionsAsUsed,
259268

269+
ObjectPattern(node) {
270+
if (node.typeAnnotation) {
271+
markTypeAnnotationAsUsed(node.typeAnnotation);
272+
}
273+
},
274+
260275
MethodDefinition(node) {
261276
if (node.decorators) {
262277
node.decorators.forEach(markDecoratorAsUsed);

Diff for: packages/eslint-plugin-typescript/tests/lib/rules/no-unused-vars.js

+16
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,22 @@ ruleTester.run("no-unused-vars", ruleNoUnusedVars, {
373373
].join("\n"),
374374
parser
375375
},
376+
{
377+
code: [
378+
"import { Nullable } from 'nullable'",
379+
"const foo = ({ nullable }: Nullable) => nullable",
380+
"foo({ nullable: null })"
381+
].join("\n"),
382+
parser
383+
},
384+
{
385+
code: [
386+
"import { ReproInterface } from 'ReproInterface'",
387+
"const x = ({ a = null } : { a: ReproInterface }) => a",
388+
"console.log(x)"
389+
].join("\n"),
390+
parser
391+
},
376392
{
377393
code: [
378394
"import { Nullable } from 'nullable'",

0 commit comments

Comments
 (0)