@@ -8,11 +8,32 @@ namespace ts.codefix {
88 function getActionsForJSDocTypes ( context : CodeFixContext ) : CodeAction [ ] | undefined {
99 const sourceFile = context . sourceFile ;
1010 const node = getTokenAtPosition ( sourceFile , context . span . start , /*includeJsDocComment*/ false ) ;
11- const decl = ts . findAncestor ( node , n => n . kind === SyntaxKind . VariableDeclaration ) ;
11+
12+ // NOTE: Some locations are not handled yet:
13+ // MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments
14+ const decl = ts . findAncestor ( node ,
15+ n =>
16+ n . kind === SyntaxKind . AsExpression ||
17+ n . kind === SyntaxKind . CallSignature ||
18+ n . kind === SyntaxKind . ConstructSignature ||
19+ n . kind === SyntaxKind . FunctionDeclaration ||
20+ n . kind === SyntaxKind . GetAccessor ||
21+ n . kind === SyntaxKind . IndexSignature ||
22+ n . kind === SyntaxKind . MappedType ||
23+ n . kind === SyntaxKind . MethodDeclaration ||
24+ n . kind === SyntaxKind . MethodSignature ||
25+ n . kind === SyntaxKind . Parameter ||
26+ n . kind === SyntaxKind . PropertyDeclaration ||
27+ n . kind === SyntaxKind . PropertySignature ||
28+ n . kind === SyntaxKind . SetAccessor ||
29+ n . kind === SyntaxKind . TypeAliasDeclaration ||
30+ n . kind === SyntaxKind . TypeAssertionExpression ||
31+ n . kind === SyntaxKind . VariableDeclaration ) ;
1232 if ( ! decl ) return ;
1333 const checker = context . program . getTypeChecker ( ) ;
1434
1535 const jsdocType = ( decl as VariableDeclaration ) . type ;
36+ if ( ! jsdocType ) return ;
1637 const original = getTextOfNode ( jsdocType ) ;
1738 const type = checker . getTypeFromTypeNode ( jsdocType ) ;
1839 const actions = [ createAction ( jsdocType , sourceFile . fileName , original , checker . typeToString ( type , /*enclosingDeclaration*/ undefined , TypeFormatFlags . NoTruncation ) ) ] ;
0 commit comments