fix(37150): ignore private fields in string index type checking (#37183)

This commit is contained in:
Alexander T 2020-04-10 19:53:53 +03:00 committed by GitHub
parent aa6be6ee6f
commit 795a5c83fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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))
}

View File

@ -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
}

View File

@ -0,0 +1,8 @@
// @target: esnext
class Foo {
[key: string]: number;
#a: boolean;
#b = false;
}