@@ -4,33 +4,43 @@ const create = (context) => {
4
4
const markTypeAsUsed = ( node ) => {
5
5
context . markVariableAsUsed ( node . id . name ) ;
6
6
} ;
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
+ } ;
7
29
8
30
return {
9
31
DeclareClass : markTypeAsUsed ,
10
32
DeclareFunction : markTypeAsUsed ,
11
33
DeclareModule : markTypeAsUsed ,
12
34
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
+ } ) ;
32
42
}
33
- }
43
+ } ) ;
34
44
}
35
45
} ;
36
46
} ;
0 commit comments