quick fix of indexed access type (#20956)

This commit is contained in:
Wenlu Wang
2018-01-05 04:45:16 +08:00
committed by Mohamed Hegazy
parent 0427d0a72b
commit 2ea5f58d60
2 changed files with 46 additions and 1 deletions

View File

@@ -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;
}

View 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;
}