mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Add a test to make sure types are being checked for privates
This commit is contained in:
parent
ba574725c2
commit
cb38c9569a
@ -4340,7 +4340,7 @@ module ts {
|
||||
var widenedType = getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true);
|
||||
if (!(isTypeAssignableTo(targetType, widenedType))) {
|
||||
checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
|
||||
}
|
||||
}
|
||||
}
|
||||
return targetType;
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
==== tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts (1 errors) ====
|
||||
interface T1 { }
|
||||
interface T2 { z }
|
||||
|
||||
class C1<T> {
|
||||
private x;
|
||||
}
|
||||
|
||||
class C2 extends C1<T1> {
|
||||
y;
|
||||
}
|
||||
|
||||
var c1: C1<T2>;
|
||||
<C2>c1; // Should succeed (private x originates in the same declaration)
|
||||
|
||||
|
||||
class C3<T> {
|
||||
private x: T; // This T is the difference between C3 and C1
|
||||
}
|
||||
|
||||
class C4 extends C3<T1> {
|
||||
y;
|
||||
}
|
||||
|
||||
var c3: C3<T2>;
|
||||
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
|
||||
~~~~~~
|
||||
!!! Neither type 'C3<T2>' nor type 'C4' is assignable to the other:
|
||||
!!! Property 'y' is missing in type 'C3<T2>'.
|
||||
@ -11,7 +11,19 @@ class C2 extends C1<T1> {
|
||||
}
|
||||
|
||||
var c1: C1<T2>;
|
||||
<C2>c1; // Should succeed (private x originates in the same declaration)
|
||||
<C2>c1; // Should succeed (private x originates in the same declaration)
|
||||
|
||||
|
||||
class C3<T> {
|
||||
private x: T; // This T is the difference between C3 and C1
|
||||
}
|
||||
|
||||
class C4 extends C3<T1> {
|
||||
y;
|
||||
}
|
||||
|
||||
var c3: C3<T2>;
|
||||
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
|
||||
|
||||
//// [objectTypesIdentityWithPrivates3.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
@ -34,3 +46,17 @@ var C2 = (function (_super) {
|
||||
})(C1);
|
||||
var c1;
|
||||
c1; // Should succeed (private x originates in the same declaration)
|
||||
var C3 = (function () {
|
||||
function C3() {
|
||||
}
|
||||
return C3;
|
||||
})();
|
||||
var C4 = (function (_super) {
|
||||
__extends(C4, _super);
|
||||
function C4() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
return C4;
|
||||
})(C3);
|
||||
var c3;
|
||||
c3; // Should fail (private x originates in the same declaration, but different types)
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
=== tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts ===
|
||||
interface T1 { }
|
||||
>T1 : T1
|
||||
|
||||
interface T2 { z }
|
||||
>T2 : T2
|
||||
>z : any
|
||||
|
||||
class C1<T> {
|
||||
>C1 : C1<T>
|
||||
>T : T
|
||||
|
||||
private x;
|
||||
>x : any
|
||||
}
|
||||
|
||||
class C2 extends C1<T1> {
|
||||
>C2 : C2
|
||||
>C1 : C1<T>
|
||||
>T1 : T1
|
||||
|
||||
y;
|
||||
>y : any
|
||||
}
|
||||
|
||||
var c1: C1<T2>;
|
||||
>c1 : C1<T2>
|
||||
>C1 : C1<T>
|
||||
>T2 : T2
|
||||
|
||||
<C2>c1; // Should succeed (private x originates in the same declaration)
|
||||
><C2>c1 : C2
|
||||
>C2 : C2
|
||||
>c1 : C1<T2>
|
||||
|
||||
@ -10,4 +10,16 @@ class C2 extends C1<T1> {
|
||||
}
|
||||
|
||||
var c1: C1<T2>;
|
||||
<C2>c1; // Should succeed (private x originates in the same declaration)
|
||||
<C2>c1; // Should succeed (private x originates in the same declaration)
|
||||
|
||||
|
||||
class C3<T> {
|
||||
private x: T; // This T is the difference between C3 and C1
|
||||
}
|
||||
|
||||
class C4 extends C3<T1> {
|
||||
y;
|
||||
}
|
||||
|
||||
var c3: C3<T2>;
|
||||
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
|
||||
Loading…
x
Reference in New Issue
Block a user