Skip to content

Hover over property accessed using ?. shows T | undefined #37879

Closed
@larsnystrom

Description

@larsnystrom

Issue Type: Bug

When I hover an object property, there is a tooltip with the type:

bild

The problem is that the type is not for the property but for the expression. This can get confusing when using optional chaining. In the screenshot above, the type of the filteredFile.reports property is actually just FilteredReport[], which is why there is no red squiggly line warning about it being potentially undefined when accessing the .length property. But the expression filteredFile?.reports has the type FilteredReport[] | undefined because of the optional chaining, which I guess is why that's the type being presented in the tooltip?

So the tooltip says (property) FilteredFile.reports: FilteredReport[] | undefined, even though the type is not for the property but for the expression. I think a better tooltip would be:

(expression) filteredFile?.reports: FilteredReport[] | undefined
(property) FilteredFile.reports: FilteredReport[]

VS Code version: Code 1.43.2 (0ba0ca52957102ca3527cf479571617f0de6ed50, 2020-03-24T07:34:57.037Z)
OS version: Darwin x64 19.4.0
Remote OS version: Linux x64 4.15.0-91-generic
TypeScript version: 3.8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions