Skip to content

Commit

Permalink
Fix: Handle extends generics in no-unused-vars (typescript-eslint#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
macklinu authored and JamesHenry committed Jan 18, 2019
1 parent 1690342 commit 8fddb6d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/eslint-plugin-typescript/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ module.exports = {

break;

case "TSTypeParameter": {
markTypeAnnotationAsUsed(annotation.constraint);
break;
}
case "TSMappedType": {
markTypeAnnotationAsUsed(annotation.typeAnnotation);
markTypeAnnotationAsUsed(annotation.typeParameter);
break;
}
default:
break;
}
Expand Down Expand Up @@ -247,6 +256,9 @@ module.exports = {
if (node.decorators) {
node.decorators.forEach(markDecoratorAsUsed);
}
if (node.typeParameters && node.typeParameters.params) {
node.typeParameters.params.forEach(markTypeAnnotationAsUsed);
}
}

//----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,30 @@ import { SomeOther } from 'some';
import { Another } from 'some';
interface A extends Nullable<SomeOther> {
do(a: Nullable<Another>);
}
`,
`
import { Foo } from './types';
class Bar<T extends Foo> {}
new Bar<number>()
`,
`
import { Foo, Bar } from './types';
class Baz<T extends Foo & Bar> {}
new Baz<any>()
`,
`
type Foo = "a" | "b" | "c"
type Bar = number
export const map: { [name in Foo]: Bar } = {
a: 1,
b: 2,
c: 3
}
`
],
Expand Down

0 comments on commit 8fddb6d

Please sign in to comment.