mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
quick fix of indexed access type (#20956)
This commit is contained in:
committed by
Mohamed Hegazy
parent
0427d0a72b
commit
2ea5f58d60
@@ -21,7 +21,7 @@ namespace ts.codefix {
|
||||
});
|
||||
|
||||
function getQualifiedName(sourceFile: SourceFile, pos: number): QualifiedName & { left: Identifier } | undefined {
|
||||
const qualifiedName = findAncestor(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ false), isQualifiedName)!;
|
||||
const qualifiedName = findAncestor(getTokenAtPosition(sourceFile, pos, /*includeJsDocComment*/ true), isQualifiedName)!;
|
||||
Debug.assert(!!qualifiedName, "Expected position to be owned by a qualified name.");
|
||||
return isIdentifier(qualifiedName.left) ? qualifiedName as QualifiedName & { left: Identifier } : undefined;
|
||||
}
|
||||
|
||||
45
tests/cases/fourslash/codeFixInPropertyAccess_js.ts
Normal file
45
tests/cases/fourslash/codeFixInPropertyAccess_js.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
//// /**
|
||||
//// * @typedef Foo
|
||||
//// * @property foo
|
||||
//// */
|
||||
|
||||
//// /**
|
||||
//// * @param {Foo.foo} inst
|
||||
//// */
|
||||
//// function blah(inst) {
|
||||
//// return false;
|
||||
//// }
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "correctQualifiedNameToIndexedAccessType",
|
||||
newFileContent:
|
||||
`/**
|
||||
* @typedef Foo
|
||||
* @property foo
|
||||
*/
|
||||
/**
|
||||
* @param {Foo["foo"]} inst
|
||||
*/
|
||||
function blah(inst) {
|
||||
return false;
|
||||
}`,
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @typedef Foo
|
||||
* @property foo
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Foo.foo} inst
|
||||
*/
|
||||
function blah(inst) {
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user