From 16ccb6637785724c2b215cb26ac2f7d727591130 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 28 Aug 2017 16:09:09 -0700 Subject: [PATCH] Provide jsdoc type code fixes for all variable-like decls This includes 3 SyntaxKinds I missed earlier: Parameter, PropertyDeclaration and PropertyAssignment. --- src/services/codefixes/fixJSDocTypes.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/codefixes/fixJSDocTypes.ts b/src/services/codefixes/fixJSDocTypes.ts index 249bc32dbf7..27c0edac628 100644 --- a/src/services/codefixes/fixJSDocTypes.ts +++ b/src/services/codefixes/fixJSDocTypes.ts @@ -8,11 +8,16 @@ namespace ts.codefix { function getActionsForJSDocTypes(context: CodeFixContext): CodeAction[] | undefined { const sourceFile = context.sourceFile; const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false); - const decl = ts.findAncestor(node, n => n.kind === SyntaxKind.VariableDeclaration); + const decl = ts.findAncestor(node, + n => n.kind === SyntaxKind.VariableDeclaration || + n.kind === SyntaxKind.Parameter || + n.kind === SyntaxKind.PropertyDeclaration || + n.kind === SyntaxKind.PropertyAssignment); if (!decl) return; const checker = context.program.getTypeChecker(); const jsdocType = (decl as VariableDeclaration).type; + if (!jsdocType) return; const original = getTextOfNode(jsdocType); const type = checker.getTypeFromTypeNode(jsdocType); const actions = [createAction(jsdocType, sourceFile.fileName, original, checker.typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.NoTruncation))];