Skip to content

Commit 795a5c8

Browse files
authored
fix(37150): ignore private fields in string index type checking (#37183)
1 parent aa6be6e commit 795a5c8

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

src/compiler/checker.ts

+4
Original file line numberDiff line numberDiff line change
@@ -32950,6 +32950,10 @@ namespace ts {
3295032950
const propDeclaration = prop.valueDeclaration;
3295132951
const name = propDeclaration && getNameOfDeclaration(propDeclaration);
3295232952

32953+
if (name && isPrivateIdentifier(name)) {
32954+
return;
32955+
}
32956+
3295332957
// index is numeric and property name is not valid numeric literal
3295432958
if (indexKind === IndexKind.Number && !(name ? isNumericName(name) : isNumericLiteralName(prop.escapedName))) {
3295532959
return;
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [classIndexer5.ts]
2+
class Foo {
3+
[key: string]: number;
4+
5+
#a: boolean;
6+
#b = false;
7+
}
8+
9+
10+
//// [classIndexer5.js]
11+
class Foo {
12+
constructor() {
13+
this.#b = false;
14+
}
15+
#a;
16+
#b;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/classIndexer5.ts ===
2+
class Foo {
3+
>Foo : Symbol(Foo, Decl(classIndexer5.ts, 0, 0))
4+
5+
[key: string]: number;
6+
>key : Symbol(key, Decl(classIndexer5.ts, 1, 5))
7+
8+
#a: boolean;
9+
>#a : Symbol(Foo.#a, Decl(classIndexer5.ts, 1, 26))
10+
11+
#b = false;
12+
>#b : Symbol(Foo.#b, Decl(classIndexer5.ts, 3, 16))
13+
}
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/classIndexer5.ts ===
2+
class Foo {
3+
>Foo : Foo
4+
5+
[key: string]: number;
6+
>key : string
7+
8+
#a: boolean;
9+
>#a : boolean
10+
11+
#b = false;
12+
>#b : boolean
13+
>false : false
14+
}
15+

tests/cases/compiler/classIndexer5.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: esnext
2+
3+
class Foo {
4+
[key: string]: number;
5+
6+
#a: boolean;
7+
#b = false;
8+
}

0 commit comments

Comments
 (0)