mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix extract type on JS function params
This commit is contained in:
@@ -68,7 +68,7 @@ namespace ts.refactor {
|
||||
if (!selection || !isTypeNode(selection)) return undefined;
|
||||
|
||||
const checker = context.program.getTypeChecker();
|
||||
const firstStatement = Debug.assertDefined(isJS ? findAncestor(selection, isStatementAndHasJSDoc) : findAncestor(selection, isStatement), "Should find a statement");
|
||||
const firstStatement = Debug.assertDefined(findAncestor(selection, isStatement), "Should find a statement");
|
||||
const typeParameters = collectTypeParameters(checker, selection, firstStatement, file);
|
||||
if (!typeParameters) return undefined;
|
||||
|
||||
@@ -100,10 +100,6 @@ namespace ts.refactor {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isStatementAndHasJSDoc(n: Node): n is (Statement & HasJSDoc) {
|
||||
return isStatement(n) && hasJSDocNodes(n);
|
||||
}
|
||||
|
||||
function rangeContainsSkipTrivia(r1: TextRange, node: Node, file: SourceFile): boolean {
|
||||
return rangeContainsStartEnd(r1, skipTrivia(file.text, node.pos), node.end);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
////function a(/** @type {/*a*/string/*b*/} */ b) {}
|
||||
|
||||
goTo.file('a.js')
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract type",
|
||||
actionName: "Extract to typedef",
|
||||
actionDescription: "Extract to typedef",
|
||||
newContent: `/**
|
||||
* @typedef {string} /*RENAME*/NewType
|
||||
*/
|
||||
|
||||
function a(/** @type {NewType} */ b) {}`,
|
||||
});
|
||||
Reference in New Issue
Block a user