Add a similar test for target.symbol.valueDeclaration

(With the same question still open.)
This commit is contained in:
Eli Barzilay
2020-01-30 22:42:04 -05:00
parent 68a9d4592f
commit 1a1ed7464d
6 changed files with 119 additions and 2 deletions
+2 -2
View File
@@ -16135,9 +16135,9 @@ namespace ts {
) {
const privateIdentifierDescription = unmatchedProperty.valueDeclaration.name.escapedText;
const symbolTableKey = getSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription);
if (symbolTableKey && !!getPropertyOfType(source, symbolTableKey)) {
if (symbolTableKey && getPropertyOfType(source, symbolTableKey)) {
const sourceName = source.symbol.valueDeclaration.name;
const targetName = isClassDeclaration(target.symbol.valueDeclaration) ? target.symbol.valueDeclaration.name : undefined;
const targetName = target.symbol.valueDeclaration && isClassDeclaration(target.symbol.valueDeclaration) ? target.symbol.valueDeclaration.name : undefined;
reportError(
Diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2,
diagnosticName(privateIdentifierDescription),
@@ -0,0 +1,21 @@
tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts(12,7): error TS2322: Type 'B' is not assignable to type 'A2'.
Property '#foo' in type 'B' refers to a different member that cannot be accessed from within type '(anonymous)'.
==== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts (1 errors) ====
// same as privateNamesUnique-1, but with an interface
class A {
#foo: number;
}
interface A2 extends A { }
class B {
#foo: number;
}
const b: A2 = new B();
~
!!! error TS2322: Type 'B' is not assignable to type 'A2'.
!!! error TS2322: Property '#foo' in type 'B' refers to a different member that cannot be accessed from within type '(anonymous)'.
@@ -0,0 +1,32 @@
//// [privateNamesUnique-5.ts]
// same as privateNamesUnique-1, but with an interface
class A {
#foo: number;
}
interface A2 extends A { }
class B {
#foo: number;
}
const b: A2 = new B();
//// [privateNamesUnique-5.js]
"use strict";
// same as privateNamesUnique-1, but with an interface
var _foo, _foo_1;
class A {
constructor() {
_foo.set(this, void 0);
}
}
_foo = new WeakMap();
class B {
constructor() {
_foo_1.set(this, void 0);
}
}
_foo_1 = new WeakMap();
const b = new B();
@@ -0,0 +1,25 @@
=== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts ===
// same as privateNamesUnique-1, but with an interface
class A {
>A : Symbol(A, Decl(privateNamesUnique-5.ts, 0, 0))
#foo: number;
>#foo : Symbol(A.#foo, Decl(privateNamesUnique-5.ts, 2, 9))
}
interface A2 extends A { }
>A2 : Symbol(A2, Decl(privateNamesUnique-5.ts, 4, 1))
>A : Symbol(A, Decl(privateNamesUnique-5.ts, 0, 0))
class B {
>B : Symbol(B, Decl(privateNamesUnique-5.ts, 5, 26))
#foo: number;
>#foo : Symbol(B.#foo, Decl(privateNamesUnique-5.ts, 7, 9))
}
const b: A2 = new B();
>b : Symbol(b, Decl(privateNamesUnique-5.ts, 11, 5))
>A2 : Symbol(A2, Decl(privateNamesUnique-5.ts, 4, 1))
>B : Symbol(B, Decl(privateNamesUnique-5.ts, 5, 26))
@@ -0,0 +1,23 @@
=== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-5.ts ===
// same as privateNamesUnique-1, but with an interface
class A {
>A : A
#foo: number;
>#foo : number
}
interface A2 extends A { }
class B {
>B : B
#foo: number;
>#foo : number
}
const b: A2 = new B();
>b : A2
>new B() : B
>B : typeof B
@@ -0,0 +1,16 @@
// @strict: true
// @target: es6
// @strictPropertyInitialization: false
// same as privateNamesUnique-1, but with an interface
class A {
#foo: number;
}
interface A2 extends A { }
class B {
#foo: number;
}
const b: A2 = new B();