@@ -4,33 +4,43 @@ const create = (context) => {
44 const markTypeAsUsed = ( node ) => {
55 context . markVariableAsUsed ( node . id . name ) ;
66 } ;
7+ const markTypeAsUsedWithGenericType = ( node ) => {
8+ let typeId ;
9+ let scope ;
10+ let variable ;
11+
12+ if ( node . id . type === 'Identifier' ) {
13+ typeId = node . id ;
14+ } else if ( node . id . type === 'QualifiedTypeIdentifier' ) {
15+ typeId = node . id ;
16+ do {
17+ typeId = typeId . qualification ;
18+ } while ( typeId . qualification ) ;
19+ }
20+
21+ for ( scope = context . getScope ( ) ; scope ; scope = scope . upper ) {
22+ variable = scope . set . get ( typeId . name ) ;
23+ if ( variable && variable . defs . length ) {
24+ context . markVariableAsUsed ( typeId . name ) ;
25+ break ;
26+ }
27+ }
28+ } ;
729
830 return {
931 DeclareClass : markTypeAsUsed ,
1032 DeclareFunction : markTypeAsUsed ,
1133 DeclareModule : markTypeAsUsed ,
1234 DeclareVariable : markTypeAsUsed ,
13- GenericTypeAnnotation ( node ) {
14- let typeId ;
15- let scope ;
16- let variable ;
17-
18- if ( node . id . type === 'Identifier' ) {
19- typeId = node . id ;
20- } else if ( node . id . type === 'QualifiedTypeIdentifier' ) {
21- typeId = node . id ;
22- do {
23- typeId = typeId . qualification ;
24- } while ( typeId . qualification ) ;
25- }
26-
27- for ( scope = context . getScope ( ) ; scope ; scope = scope . upper ) {
28- variable = scope . set . get ( typeId . name ) ;
29- if ( variable && variable . defs . length ) {
30- context . markVariableAsUsed ( typeId . name ) ;
31- break ;
35+ GenericTypeAnnotation : markTypeAsUsedWithGenericType ,
36+ TypeParameterDeclaration ( node ) {
37+ node . params . forEach ( ( param ) => {
38+ if ( param . default && param . default . typeParameters ) {
39+ param . default . typeParameters . params . forEach ( ( typeParameterNode ) => {
40+ markTypeAsUsedWithGenericType ( typeParameterNode ) ;
41+ } ) ;
3242 }
33- }
43+ } ) ;
3444 }
3545 } ;
3646} ;
0 commit comments