Skip to content

Bad completions for string literal type as indexed access type object #40322

@DanielRosenwasser

Description

@DanielRosenwasser

Found while reading over #39697

let x: ""["bar"]

Request completions inside of "" and you'll get the names of every propery on String. What's happening is that we're not checking to see if the current string literal type is the argument type (as opposed to the object type itself).

Learning how this works might be a bit involved, but the fix is easy: add fourslash tests, add a single if check at

case SyntaxKind.IndexedAccessType:
// Get all apparent property names
// i.e. interface Foo {
// foo: string;
// bar: string;
// }
// let x: Foo["/*completion position*/"]
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode((parent.parent as IndexedAccessTypeNode).objectType));

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editorGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions