Skip to content

Commit 16ccb66

Browse files
committed
Provide jsdoc type code fixes for all variable-like decls
This includes 3 SyntaxKinds I missed earlier: Parameter, PropertyDeclaration and PropertyAssignment.
1 parent 934da9f commit 16ccb66

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/services/codefixes/fixJSDocTypes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ 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+
const decl = ts.findAncestor(node,
12+
n => n.kind === SyntaxKind.VariableDeclaration ||
13+
n.kind === SyntaxKind.Parameter ||
14+
n.kind === SyntaxKind.PropertyDeclaration ||
15+
n.kind === SyntaxKind.PropertyAssignment);
1216
if (!decl) return;
1317
const checker = context.program.getTypeChecker();
1418

1519
const jsdocType = (decl as VariableDeclaration).type;
20+
if (!jsdocType) return;
1621
const original = getTextOfNode(jsdocType);
1722
const type = checker.getTypeFromTypeNode(jsdocType);
1823
const actions = [createAction(jsdocType, sourceFile.fileName, original, checker.typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.NoTruncation))];

0 commit comments

Comments
 (0)