@@ -64,17 +64,21 @@ namespace ts.codefix {
64
64
return undefined ;
65
65
}
66
66
67
+ const { parent } = token ;
67
68
switch ( errorCode ) {
68
69
// Variable and Property declarations
69
70
case Diagnostics . Member_0_implicitly_has_an_1_type . code :
70
71
case Diagnostics . Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined . code :
71
- annotateVariableDeclaration ( changes , sourceFile , < PropertyDeclaration | PropertySignature | VariableDeclaration > token . parent , program , cancellationToken ) ;
72
- return token . parent as Declaration ;
72
+ if ( isVariableDeclaration ( parent ) || isPropertyDeclaration ( parent ) || isPropertySignature ( parent ) ) { // handle bad location
73
+ annotateVariableDeclaration ( changes , sourceFile , parent , program , cancellationToken ) ;
74
+ return parent ;
75
+ }
76
+ return undefined ;
73
77
74
78
case Diagnostics . Variable_0_implicitly_has_an_1_type . code : {
75
79
const symbol = program . getTypeChecker ( ) . getSymbolAtLocation ( token ) ;
76
- if ( symbol && symbol . valueDeclaration ) {
77
- annotateVariableDeclaration ( changes , sourceFile , < VariableDeclaration > symbol . valueDeclaration , program , cancellationToken ) ;
80
+ if ( symbol && symbol . valueDeclaration && isVariableDeclaration ( symbol . valueDeclaration ) ) {
81
+ annotateVariableDeclaration ( changes , sourceFile , symbol . valueDeclaration , program , cancellationToken ) ;
78
82
return symbol . valueDeclaration ;
79
83
}
80
84
}
@@ -95,7 +99,7 @@ namespace ts.codefix {
95
99
// falls through
96
100
case Diagnostics . Rest_parameter_0_implicitly_has_an_any_type . code :
97
101
if ( ! seenFunctions || addToSeen ( seenFunctions , getNodeId ( containingFunction ) ) ) {
98
- const param = cast ( token . parent , isParameter ) ;
102
+ const param = cast ( parent , isParameter ) ;
99
103
annotateParameters ( changes , param , containingFunction , sourceFile , program , cancellationToken ) ;
100
104
return param ;
101
105
}
0 commit comments