Skip to content

Commit 9df593b

Browse files
TypeScript Botandrewbranch
authored andcommitted
Cherry-pick PR microsoft#34745 into release-3.7 (microsoft#34766)
Component commits: 07a371b Fix extract type on JS function params
1 parent 6317c90 commit 9df593b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/services/refactors/extractType.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace ts.refactor {
6868
if (!selection || !isTypeNode(selection)) return undefined;
6969

7070
const checker = context.program.getTypeChecker();
71-
const firstStatement = Debug.assertDefined(isJS ? findAncestor(selection, isStatementAndHasJSDoc) : findAncestor(selection, isStatement), "Should find a statement");
71+
const firstStatement = Debug.assertDefined(findAncestor(selection, isStatement), "Should find a statement");
7272
const typeParameters = collectTypeParameters(checker, selection, firstStatement, file);
7373
if (!typeParameters) return undefined;
7474

@@ -100,10 +100,6 @@ namespace ts.refactor {
100100
return undefined;
101101
}
102102

103-
function isStatementAndHasJSDoc(n: Node): n is (Statement & HasJSDoc) {
104-
return isStatement(n) && hasJSDocNodes(n);
105-
}
106-
107103
function rangeContainsSkipTrivia(r1: TextRange, node: Node, file: SourceFile): boolean {
108104
return rangeContainsStartEnd(r1, skipTrivia(file.text, node.pos), node.end);
109105
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJs: true
4+
// @Filename: a.js
5+
////function a(/** @type {/*a*/string/*b*/} */ b) {}
6+
7+
goTo.file('a.js')
8+
goTo.select("a", "b");
9+
edit.applyRefactor({
10+
refactorName: "Extract type",
11+
actionName: "Extract to typedef",
12+
actionDescription: "Extract to typedef",
13+
newContent: `/**
14+
* @typedef {string} /*RENAME*/NewType
15+
*/
16+
17+
function a(/** @type {NewType} */ b) {}`,
18+
});

0 commit comments

Comments
 (0)