Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1a1ed74

Browse filesBrowse files
committed
Add a similar test for target.symbol.valueDeclaration
(With the same question still open.)
1 parent 68a9d45 commit 1a1ed74
Copy full SHA for 1a1ed74

File tree

Expand file treeCollapse file tree

6 files changed

+119
-2
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+119
-2
lines changed

‎src/compiler/checker.ts

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16135,9 +16135,9 @@ namespace ts {
1613516135
) {
1613616136
const privateIdentifierDescription = unmatchedProperty.valueDeclaration.name.escapedText;
1613716137
const symbolTableKey = getSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription);
16138-
if (symbolTableKey && !!getPropertyOfType(source, symbolTableKey)) {
16138+
if (symbolTableKey && getPropertyOfType(source, symbolTableKey)) {
1613916139
const sourceName = source.symbol.valueDeclaration.name;
16140-
const targetName = isClassDeclaration(target.symbol.valueDeclaration) ? target.symbol.valueDeclaration.name : undefined;
16140+
const targetName = target.symbol.valueDeclaration && isClassDeclaration(target.symbol.valueDeclaration) ? target.symbol.valueDeclaration.name : undefined;
1614116141
reportError(
1614216142
Diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2,
1614316143
diagnosticName(privateIdentifierDescription),
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts(12,7): error TS2322: Type 'B' is not assignable to type 'A2'.
2+
Property '#foo' in type 'B' refers to a different member that cannot be accessed from within type '(anonymous)'.
3+
4+
5+
==== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts (1 errors) ====
6+
// same as privateNamesUnique-1, but with an interface
7+
8+
class A {
9+
#foo: number;
10+
}
11+
interface A2 extends A { }
12+
13+
class B {
14+
#foo: number;
15+
}
16+
17+
const b: A2 = new B();
18+
~
19+
!!! error TS2322: Type 'B' is not assignable to type 'A2'.
20+
!!! error TS2322: Property '#foo' in type 'B' refers to a different member that cannot be accessed from within type '(anonymous)'.
21+
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [privateNamesUnique-5.ts]
2+
// same as privateNamesUnique-1, but with an interface
3+
4+
class A {
5+
#foo: number;
6+
}
7+
interface A2 extends A { }
8+
9+
class B {
10+
#foo: number;
11+
}
12+
13+
const b: A2 = new B();
14+
15+
16+
//// [privateNamesUnique-5.js]
17+
"use strict";
18+
// same as privateNamesUnique-1, but with an interface
19+
var _foo, _foo_1;
20+
class A {
21+
constructor() {
22+
_foo.set(this, void 0);
23+
}
24+
}
25+
_foo = new WeakMap();
26+
class B {
27+
constructor() {
28+
_foo_1.set(this, void 0);
29+
}
30+
}
31+
_foo_1 = new WeakMap();
32+
const b = new B();
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts ===
2+
// same as privateNamesUnique-1, but with an interface
3+
4+
class A {
5+
>A : Symbol(A, Decl(privateNamesUnique-5.ts, 0, 0))
6+
7+
#foo: number;
8+
>#foo : Symbol(A.#foo, Decl(privateNamesUnique-5.ts, 2, 9))
9+
}
10+
interface A2 extends A { }
11+
>A2 : Symbol(A2, Decl(privateNamesUnique-5.ts, 4, 1))
12+
>A : Symbol(A, Decl(privateNamesUnique-5.ts, 0, 0))
13+
14+
class B {
15+
>B : Symbol(B, Decl(privateNamesUnique-5.ts, 5, 26))
16+
17+
#foo: number;
18+
>#foo : Symbol(B.#foo, Decl(privateNamesUnique-5.ts, 7, 9))
19+
}
20+
21+
const b: A2 = new B();
22+
>b : Symbol(b, Decl(privateNamesUnique-5.ts, 11, 5))
23+
>A2 : Symbol(A2, Decl(privateNamesUnique-5.ts, 4, 1))
24+
>B : Symbol(B, Decl(privateNamesUnique-5.ts, 5, 26))
25+
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts ===
2+
// same as privateNamesUnique-1, but with an interface
3+
4+
class A {
5+
>A : A
6+
7+
#foo: number;
8+
>#foo : number
9+
}
10+
interface A2 extends A { }
11+
12+
class B {
13+
>B : B
14+
15+
#foo: number;
16+
>#foo : number
17+
}
18+
19+
const b: A2 = new B();
20+
>b : A2
21+
>new B() : B
22+
>B : typeof B
23+
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @strict: true
2+
// @target: es6
3+
// @strictPropertyInitialization: false
4+
5+
// same as privateNamesUnique-1, but with an interface
6+
7+
class A {
8+
#foo: number;
9+
}
10+
interface A2 extends A { }
11+
12+
class B {
13+
#foo: number;
14+
}
15+
16+
const b: A2 = new B();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.