Skip to content

Tooltip on private fields not showing the correct type after narrowingΒ #43346

Closed
@SuspiciousLookingOwl

Description

@SuspiciousLookingOwl

Bug Report

πŸ”Ž Search Terms

private field, class, narrow, narrowing

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class TestClass {
    #privateProperty: string[] | null;
    publicProperty: string[] | null;

    constructor() {
        this.#privateProperty = null;
        this.publicProperty = null;
    }

    testMethod() {
        if (this.#privateProperty === null)
            return;
        if (this.publicProperty === null)
            return;

        this.#privateProperty; // string[] | null
        this.publicProperty; // string[]

        const a = this.#privateProperty;
        a; // string[]
    }
}

πŸ™ Actual behavior

this.#privateProperty is string[] | null even after narrowing down the type from if. Also assigning this.#privateProperty to other variable fixes the type.

πŸ™‚ Expected behavior

this.#privateProperty should be string[] after narrowing down

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Quick Infoe.g. hover text, tool-tips, and tooltips.Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions