diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a98fd289a390..1644f888115cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23546,7 +23546,7 @@ namespace ts { // an dotted name expression, and if the location is not an assignment target, obtain the type // of the expression (which will reflect control flow analysis). If the expression indeed // resolved to the given symbol, return the narrowed type. - if (location.kind === SyntaxKind.Identifier) { + if (location.kind === SyntaxKind.Identifier || location.kind === SyntaxKind.PrivateIdentifier) { if (isRightSideOfQualifiedNameOrPropertyAccess(location)) { location = location.parent; } diff --git a/tests/cases/fourslash/quickInfoOnNarrowedType.ts b/tests/cases/fourslash/quickInfoOnNarrowedType.ts index da9a7ba0c7ac1..5b0c9a0f14e36 100644 --- a/tests/cases/fourslash/quickInfoOnNarrowedType.ts +++ b/tests/cases/fourslash/quickInfoOnNarrowedType.ts @@ -18,6 +18,18 @@ //// /*6*/s; ////} +////class Foo { +//// #privateProperty: string[] | null; +//// constructor() { +//// this.#privateProperty = null; +//// } +//// testMethod() { +//// if (this.#privateProperty === null) +//// return; +//// this./*7*/#privateProperty; +//// } +////} + verify.quickInfos({ 1: "(parameter) strOrNum: string | number", 2: "(parameter) strOrNum: number", @@ -25,6 +37,7 @@ verify.quickInfos({ 4: "let s: string | undefined", 5: "let s: string | undefined", 6: "let s: string", + 7: "(property) Foo.#privateProperty: string[]" }); verify.completions( @@ -33,4 +46,5 @@ verify.completions( { marker: "3", includes: { name: "strOrNum", text: "(parameter) strOrNum: string" } }, { marker: ["4", "5"], includes: { name: "s", text: "let s: string | undefined" } }, { marker: "6", includes: { name: "s", text: "let s: string" } }, + { marker: "7", includes: { name: "#privateProperty", text: "(property) Foo.#privateProperty: string[]" } } );