Add circularity tests

This commit is contained in:
Anders Hejlsberg 2016-12-08 06:53:29 -08:00
parent ca2768caf6
commit 311bb3b2da
3 changed files with 158 additions and 0 deletions

View file

@ -0,0 +1,57 @@
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(3,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(7,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(15,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(19,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(23,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(27,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(28,5): error TS2502: 'y' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(29,5): error TS2502: 'z' is referenced directly or indirectly in its own type annotation.
==== tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts (8 errors) ====
type T1 = {
x: T1["x"]; // Error
~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
};
type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
~~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
y: number;
}
declare let x2: T2<"x">;
let x2x = x2.x;
interface T3<T extends T3<T>> {
x: T["x"]; // Error
~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}
interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
~~~~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}
class C1 {
x: C1["x"]; // Error
~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}
class C2 {
x: this["y"]; // Error
~~~~~~~~~~~~~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
y: this["z"]; // Error
~~~~~~~~~~~~~
!!! error TS2502: 'y' is referenced directly or indirectly in its own type annotation.
z: this["x"]; // Error
~~~~~~~~~~~~~
!!! error TS2502: 'z' is referenced directly or indirectly in its own type annotation.
}

View file

@ -0,0 +1,70 @@
//// [circularIndexedAccessErrors.ts]
type T1 = {
x: T1["x"]; // Error
};
type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
y: number;
}
declare let x2: T2<"x">;
let x2x = x2.x;
interface T3<T extends T3<T>> {
x: T["x"]; // Error
}
interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
}
class C1 {
x: C1["x"]; // Error
}
class C2 {
x: this["y"]; // Error
y: this["z"]; // Error
z: this["x"]; // Error
}
//// [circularIndexedAccessErrors.js]
var x2x = x2.x;
var C1 = (function () {
function C1() {
}
return C1;
}());
var C2 = (function () {
function C2() {
}
return C2;
}());
//// [circularIndexedAccessErrors.d.ts]
declare type T1 = {
x: T1["x"];
};
declare type T2<K extends "x" | "y"> = {
x: T2<K>[K];
y: number;
};
declare let x2: T2<"x">;
declare let x2x: any;
interface T3<T extends T3<T>> {
x: T["x"];
}
interface T4<T extends T4<T>> {
x: T4<T>["x"];
}
declare class C1 {
x: C1["x"];
}
declare class C2 {
x: this["y"];
y: this["z"];
z: this["x"];
}

View file

@ -0,0 +1,31 @@
// @declaration: true
type T1 = {
x: T1["x"]; // Error
};
type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
y: number;
}
declare let x2: T2<"x">;
let x2x = x2.x;
interface T3<T extends T3<T>> {
x: T["x"]; // Error
}
interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
}
class C1 {
x: C1["x"]; // Error
}
class C2 {
x: this["y"]; // Error
y: this["z"]; // Error
z: this["x"]; // Error
}