diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5685502aec3..711cb06bdea 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32950,6 +32950,10 @@ namespace ts { const propDeclaration = prop.valueDeclaration; const name = propDeclaration && getNameOfDeclaration(propDeclaration); + if (name && isPrivateIdentifier(name)) { + return; + } + // index is numeric and property name is not valid numeric literal if (indexKind === IndexKind.Number && !(name ? isNumericName(name) : isNumericLiteralName(prop.escapedName))) { return; diff --git a/tests/baselines/reference/classIndexer5.js b/tests/baselines/reference/classIndexer5.js new file mode 100644 index 00000000000..43c65fc4e80 --- /dev/null +++ b/tests/baselines/reference/classIndexer5.js @@ -0,0 +1,17 @@ +//// [classIndexer5.ts] +class Foo { + [key: string]: number; + + #a: boolean; + #b = false; +} + + +//// [classIndexer5.js] +class Foo { + constructor() { + this.#b = false; + } + #a; + #b; +} diff --git a/tests/baselines/reference/classIndexer5.symbols b/tests/baselines/reference/classIndexer5.symbols new file mode 100644 index 00000000000..6f7cabe2856 --- /dev/null +++ b/tests/baselines/reference/classIndexer5.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/classIndexer5.ts === +class Foo { +>Foo : Symbol(Foo, Decl(classIndexer5.ts, 0, 0)) + + [key: string]: number; +>key : Symbol(key, Decl(classIndexer5.ts, 1, 5)) + + #a: boolean; +>#a : Symbol(Foo.#a, Decl(classIndexer5.ts, 1, 26)) + + #b = false; +>#b : Symbol(Foo.#b, Decl(classIndexer5.ts, 3, 16)) +} + diff --git a/tests/baselines/reference/classIndexer5.types b/tests/baselines/reference/classIndexer5.types new file mode 100644 index 00000000000..23708b247c9 --- /dev/null +++ b/tests/baselines/reference/classIndexer5.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/classIndexer5.ts === +class Foo { +>Foo : Foo + + [key: string]: number; +>key : string + + #a: boolean; +>#a : boolean + + #b = false; +>#b : boolean +>false : false +} + diff --git a/tests/cases/compiler/classIndexer5.ts b/tests/cases/compiler/classIndexer5.ts new file mode 100644 index 00000000000..7ca7f208e3d --- /dev/null +++ b/tests/cases/compiler/classIndexer5.ts @@ -0,0 +1,8 @@ +// @target: esnext + +class Foo { + [key: string]: number; + + #a: boolean; + #b = false; +}