Skip to content

Commit 2ea5f58

Browse files
Kingwlmhegazy
authored andcommitted
quick fix of indexed access type (#20956)
1 parent 0427d0a commit 2ea5f58

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/services/codefixes/correctQualifiedNameToIndexedAccessType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace ts.codefix {
2121
});
2222

2323
function getQualifiedName(sourceFile: SourceFile, pos: number): QualifiedName & { left: Identifier } | undefined {
24-
const qualifiedName = findAncestor(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false), isQualifiedName)!;
24+
const qualifiedName = findAncestor(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ true), isQualifiedName)!;
2525
Debug.assert(!!qualifiedName, "Expected position to be owned by a qualified name.");
2626
return isIdentifier(qualifiedName.left) ? qualifiedName as QualifiedName & { left: Identifier } : undefined;
2727
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJs: true
4+
// @checkJs: true
5+
6+
// @Filename: /a.js
7+
//// /**
8+
//// * @typedef Foo
9+
//// * @property foo
10+
//// */
11+
12+
//// /**
13+
//// * @param {Foo.foo} inst
14+
//// */
15+
//// function blah(inst) {
16+
//// return false;
17+
//// }
18+
19+
verify.codeFixAll({
20+
fixId: "correctQualifiedNameToIndexedAccessType",
21+
newFileContent:
22+
`/**
23+
* @typedef Foo
24+
* @property foo
25+
*/
26+
/**
27+
* @param {Foo["foo"]} inst
28+
*/
29+
function blah(inst) {
30+
return false;
31+
}`,
32+
});
33+
34+
35+
/**
36+
* @typedef Foo
37+
* @property foo
38+
*/
39+
40+
/**
41+
* @param {Foo.foo} inst
42+
*/
43+
function blah(inst) {
44+
return false;
45+
}

0 commit comments

Comments
 (0)