Merge pull request #29446 from fuafa/infer-js-doc
fix quick fix infer parameter types from usage in js file
This commit is contained in:
commit
a856a64a5c
2 changed files with 38 additions and 1 deletions
|
@ -274,7 +274,17 @@ namespace ts.codefix {
|
|||
return !!merged;
|
||||
}));
|
||||
const tag = createJSDocComment(comments.join("\n"), createNodeArray([...(oldTags || emptyArray), ...unmergedNewTags]));
|
||||
changes.insertJsdocCommentBefore(sourceFile, parent, tag);
|
||||
const jsDocNode = parent.kind === SyntaxKind.ArrowFunction ? getJsDocNodeForArrowFunction(parent) : parent;
|
||||
jsDocNode.jsDoc = parent.jsDoc;
|
||||
jsDocNode.jsDocCache = parent.jsDocCache;
|
||||
changes.insertJsdocCommentBefore(sourceFile, jsDocNode, tag);
|
||||
}
|
||||
|
||||
function getJsDocNodeForArrowFunction(signature: ArrowFunction): HasJSDoc {
|
||||
if (signature.parent.kind === SyntaxKind.PropertyDeclaration) {
|
||||
return <HasJSDoc>signature.parent;
|
||||
}
|
||||
return <HasJSDoc>signature.parent.parent;
|
||||
}
|
||||
|
||||
function tryMergeJsdocTags(oldTag: JSDocTag, newTag: JSDocTag): JSDocTag | undefined {
|
||||
|
|
27
tests/cases/fourslash/codeFixInferFromUsageArrowJS.ts
Normal file
27
tests/cases/fourslash/codeFixInferFromUsageArrowJS.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @noImplicitAny: true
|
||||
// @Filename: test.js
|
||||
|
||||
////const foo = x => x.y + 1;
|
||||
////class C {
|
||||
//// m = x => x.y + 1;
|
||||
////}
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "inferFromUsage",
|
||||
fixAllDescription: "Infer all types from usage",
|
||||
newFileContent:
|
||||
`/**
|
||||
* @param {{ y: number; }} x
|
||||
*/
|
||||
const foo = x => x.y + 1;
|
||||
class C {
|
||||
/**
|
||||
* @param {{ y: number; }} x
|
||||
*/
|
||||
m = x => x.y + 1;
|
||||
}`,
|
||||
});
|
Loading…
Reference in a new issue