fix(40322): bad completions for string literal type as indexed access type object (#40424)

* Added fourslash tests to work on the bug

* fix(40322): bad completions for string literal type as indexed access type object

* Added regression tests

* Using nodes instead of text

* Add verification for parenthesized nodes

* Using range check

* Change test markers
This commit is contained in:
Vincent Boivin
2020-09-09 18:26:35 -04:00
committed by GitHub
parent ee5f51bc0f
commit 96b0832cf6
2 changed files with 52 additions and 1 deletions

View File

@@ -130,7 +130,11 @@ namespace ts.Completions.StringCompletions {
// bar: string;
// }
// let x: Foo["/*completion position*/"]
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode((grandParent as IndexedAccessTypeNode).objectType));
const { indexType, objectType } = grandParent as IndexedAccessTypeNode;
if (!rangeContainsPosition(indexType, position)) {
return undefined;
}
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode(objectType));
case SyntaxKind.ImportType:
return { kind: StringLiteralCompletionKind.Paths, paths: getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker) };
case SyntaxKind.UnionType: {