Skip to content

Commit 88b47d4

Browse files
committed
getLiteralTypeFromPropertyName hides private names
Signed-off-by: Max Heiber <max.heiber@gmail.com>
1 parent d7576d5 commit 88b47d4

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9044,7 +9044,9 @@ namespace ts {
90449044
}
90459045

90469046
function getLiteralTypeFromPropertyName(prop: Symbol, include: TypeFlags) {
9047-
if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier)) {
9047+
const hasNonPublicModifier = !!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier);
9048+
const hasPrivateName = prop.valueDeclaration && isNamedDeclaration(prop.valueDeclaration) && isPrivateName(prop.valueDeclaration.name);
9049+
if (!hasNonPublicModifier && !hasPrivateName) {
90489050
let type = getLateBoundSymbol(prop).nameType;
90499051
if (!type && !isKnownSymbol(prop)) {
90509052
const name = prop.valueDeclaration && getNameOfDeclaration(prop.valueDeclaration);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [privateNamesAndkeyof.ts]
2+
class A {
3+
#foo;
4+
bar;
5+
baz;
6+
}
7+
8+
type T = keyof A // should not include '#foo'
9+
10+
11+
//// [privateNamesAndkeyof.js]
12+
var A = /** @class */ (function () {
13+
function A() {
14+
}
15+
return A;
16+
}());
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts ===
2+
class A {
3+
>A : Symbol(A, Decl(privateNamesAndkeyof.ts, 0, 0))
4+
5+
#foo;
6+
>#foo : Symbol(A[#foo], Decl(privateNamesAndkeyof.ts, 0, 9))
7+
8+
bar;
9+
>bar : Symbol(A.bar, Decl(privateNamesAndkeyof.ts, 1, 9))
10+
11+
baz;
12+
>baz : Symbol(A.baz, Decl(privateNamesAndkeyof.ts, 2, 8))
13+
}
14+
15+
type T = keyof A // should not include '#foo'
16+
>T : Symbol(T, Decl(privateNamesAndkeyof.ts, 4, 1))
17+
>A : Symbol(A, Decl(privateNamesAndkeyof.ts, 0, 0))
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts ===
2+
class A {
3+
>A : A
4+
5+
#foo;
6+
>#foo : any
7+
8+
bar;
9+
>bar : any
10+
11+
baz;
12+
>baz : any
13+
}
14+
15+
type T = keyof A // should not include '#foo'
16+
>T : "bar" | "baz"
17+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
#foo;
3+
bar;
4+
baz;
5+
}
6+
7+
type T = keyof A // should not include '#foo'

0 commit comments

Comments
 (0)