fix quick fix infer parameter types from usage in js file

This commit is contained in:
xiaofa 2019-01-17 05:51:57 +08:00
parent a9c5a0472f
commit c9c9f859f3
2 changed files with 21 additions and 1 deletions

View file

@ -340,7 +340,9 @@ namespace ts.textChanges {
}
public insertJsdocCommentBefore(sourceFile: SourceFile, node: HasJSDoc, tag: JSDoc): void {
const fnStart = node.getStart(sourceFile);
const fnStart = node.kind === SyntaxKind.ArrowFunction
? node.parent.parent.getStart(sourceFile)
: node.getStart(sourceFile);
if (node.jsDoc) {
for (const jsdoc of node.jsDoc) {
this.deleteRange(sourceFile, {

View file

@ -0,0 +1,18 @@
/// <reference path='fourslash.ts' />
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @noImplicitAny: true
// @Filename: test.js
////const foo = x => x.y + 1;
verify.codeFix({
description: "Infer parameter types from usage",
index: 0,
newFileContent:
`/**
* @param {{ y: number; }} x
*/
const foo = x => x.y + 1;`,
});