Skip to content

Commit 84bc7e9

Browse files
author
Max Heiber
committed
handle private name with index signature
"Property _ does not exist on type _" error should still happen with private names even if the class has an index signature (new test case) Signed-off-by: Max Heiber <mheiber@bloomberg.net>
1 parent 734bd76 commit 84bc7e9

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17780,7 +17780,7 @@ namespace ts {
1778017780
}
1778117781
if (!prop) {
1778217782
const indexInfo = getIndexInfoOfType(apparentType, IndexKind.String);
17783-
if (!(indexInfo && indexInfo.type)) {
17783+
if (!(indexInfo && indexInfo.type) || isPrivateName(right)) {
1778417784
if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
1778517785
reportNonexistentProperty(right, leftType.flags & TypeFlags.TypeParameter && (leftType as TypeParameter).isThisType ? apparentType : leftType);
1778617786
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts(4,14): error TS2339: Property '#f' does not exist on type 'A'.
2+
3+
4+
==== tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts (1 errors) ====
5+
class A {
6+
[k: string]: any;
7+
constructor(message: string) {
8+
this.#f = 3 // Error Property '#f' does not exist on type 'A'.
9+
~~
10+
!!! error TS2339: Property '#f' does not exist on type 'A'.
11+
}
12+
}
13+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [privateNameAndIndexSignature.ts]
2+
class A {
3+
[k: string]: any;
4+
constructor(message: string) {
5+
this.#f = 3 // Error Property '#f' does not exist on type 'A'.
6+
}
7+
}
8+
9+
10+
//// [privateNameAndIndexSignature.js]
11+
var A = /** @class */ (function () {
12+
function A(message) {
13+
this.#f = 3; // Error Property '#f' does not exist on type 'A'.
14+
}
15+
return A;
16+
}());
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts ===
2+
class A {
3+
>A : Symbol(A, Decl(privateNameAndIndexSignature.ts, 0, 0))
4+
5+
[k: string]: any;
6+
>k : Symbol(k, Decl(privateNameAndIndexSignature.ts, 1, 5))
7+
8+
constructor(message: string) {
9+
>message : Symbol(message, Decl(privateNameAndIndexSignature.ts, 2, 16))
10+
11+
this.#f = 3 // Error Property '#f' does not exist on type 'A'.
12+
>this : Symbol(A, Decl(privateNameAndIndexSignature.ts, 0, 0))
13+
}
14+
}
15+
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/privateNameAndIndexSignature.ts ===
2+
class A {
3+
>A : A
4+
5+
[k: string]: any;
6+
>k : string
7+
8+
constructor(message: string) {
9+
>message : string
10+
11+
this.#f = 3 // Error Property '#f' does not exist on type 'A'.
12+
>this.#f = 3 : 3
13+
>this.#f : any
14+
>this : this
15+
>3 : 3
16+
}
17+
}
18+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A {
2+
[k: string]: any;
3+
constructor(message: string) {
4+
this.#f = 3 // Error Property '#f' does not exist on type 'A'.
5+
}
6+
}

0 commit comments

Comments
 (0)