Skip to content

Object type literal with string literal property in contextual typing position causes language service error on all literal type references #50750

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

In a TypeScript file

interface SomeType {
    property: "foo";
}

/**
 * @type {{ property: "foo"}}
 */
const obj: SomeType = {
    property: "foo",
};

Request find-all-references on any string literal. This currently produces the following language service error:

<semantic> Response received: references (1602). Request took 7 ms. Success: false . Message: Error processing request. Cannot read properties of undefined (reading 'flags')
TypeError: Cannot read properties of undefined (reading 'flags')
    at getMembersOfSymbol (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:58736:27)
    at getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:63766:21)
    at getTypeFromTypeNodeWorker (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:64161:28)
    at getTypeFromTypeNode (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:64085:49)
    at getTypeOfNode (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:87993:40)
    at Object.getTypeAtLocation (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:49147:31)
    at Object.getContextualTypeFromParentOrAncestorTypeNode (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:129138:44)
    at c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:140822:50
    at Object.mapDefined (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:621:30)
    at c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:140819:31
    at Object.flatMap (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:524:25)
    at getReferencesForStringLiteral (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:140817:37)
    at Object.getReferencedSymbolsForNode (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:139547:32)
    at Object.findReferencedSymbols (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:139142:42)
    at Object.findReferences (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:168023:41)
    at c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:178178:53
    at searchPosition (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:178375:38)
    at getPerProjectReferences (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:178343:42)
    at getReferencesWorker (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:178175:37)
    at Session.getReferences (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:179778:34)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (c:/Users/Daniel/.vscode-insiders/extensions/ms-vscode.vscode-typescript-next-4.9.20220911/node_modules/typescript/lib/tsserver.js:178615:61)

Found from https://github.com/mermaid-js/mermaid/blob/3d32280c49125c135cf08a3086e184971a1c6f85/src/utils.ts#L528

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Fix AvailableA PR has been opened for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions