TypeScript/tests/baselines/reference/recursiveTypesWithTypeof.types
Anders Hejlsberg 0e905be42b
Index signatures for symbols and template literal strings (#44512)
* Switch index signature storage to 'indexInfos: IndexInfo[]' property

* Accept new baselines

* Remove another usage of IndexKind enum

* Update getIndexedAccessType and resolveMappedTypeMembers

* Accept new baselines

* Update grammar checking for index signatures

* Accept new baselines

* Consider all index signatures in mapped types and union types

* Accept new baselines

* Update getIndexType

* Accept new baselines

* Intersect multiple applicable index signatures

* Use getApplicableIndexInfo instead of hardwired string/number handling

* Update index signature relationship checking

* Report type for which index signature is missing

* Report type for which index signature is missing

* Accept new baselines

* Make 'number' index signatures consistently apply to numeric strings

* Accept new baselines

* Update fourslash test

* Revise index constraint checking

* Accept new baselines

* Update error messages

* Accept new baselines

* Update type inference from index signatures

* Update isKnownProperty

* Update contextual typing based on index signatures

* Accept new baselines

* Support union types in index signature declarations

* Accept new baselines

* Check duplicate index signatures / remove redundant template literals from unions with string

* Accept new baselines

* Include key type in diagnostic / check symbol-named properties

* Accept new baselines

* Minor fix

* Add tests

* Accept new baselines

* Add optimized findApplicableIndexInfoForName

* Accept new baselines

* Another place we don't need to obtain literal type for property name

* Accept new baselines

* Don't create literal types that are going to be discarded

* Individual maps for string, number, bigint, and enum literal types

* Remove ineffective optimizations

* Accept new baselines

* Permit intersections as key types in index signatures

* Index expression in element access is template literal context

* Add tests

* Accept new baselines

* Symbol index signatures from object literals with computed symbol properties

* Accept new baselines

* Add more tests

* Accept new baselines

* Implement Go To Definition for all applicable index signatures

* Add fourslash test

* Accept new API baselines
2021-06-21 11:25:42 -07:00

184 lines
3.7 KiB
Plaintext

=== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts ===
// The following are errors because of circular references
var c: typeof c;
>c : any
>c : any
var c: any;
>c : any
var d: typeof e;
>d : any
>e : any
var d: any;
>d : any
var e: typeof d;
>e : any
>d : any
var e: any;
>e : any
interface Foo<T> { }
var f: Array<typeof f>;
>f : any
>f : any
var f: any;
>f : any
var f2: Foo<typeof f2>;
>f2 : any
>f2 : any
var f2: any;
>f2 : any
var f3: Foo<typeof f3>[];
>f3 : any
>f3 : any
var f3: any;
>f3 : any
// None of these declarations should have any errors!
// Truly recursive types
var g: { x: typeof g; };
>g : { x: typeof g; }
>x : { x: typeof g; }
>g : { x: any; }
var g: typeof g.x;
>g : { x: any; }
>g.x : { x: any; }
>g : { x: any; }
>x : { x: any; }
var h: () => typeof h;
>h : () => typeof h
>h : () => typeof h
var h = h();
>h : () => any
>h() : () => any
>h : () => any
var i: (x: typeof i) => typeof x;
>i : (x: typeof i) => any
>x : (x: typeof i) => any
>i : (x: any) => any
>x : (x: any) => typeof x
var i = i(i);
>i : (x: any) => any
>i(i) : (x: any) => any
>i : (x: any) => any
>i : (x: any) => any
var j: <T extends typeof j>(x: T) => T;
>j : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
>x : T
var j = j(j);
>j : <T extends any>(x: T) => T
>j(j) : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
>h2 : new () => typeof h2
>h2 : new () => typeof h2
var h2 = new h2();
>h2 : new () => any
>new h2() : new () => any
>h2 : new () => any
var i2: new (x: typeof i2) => typeof x;
>i2 : new (x: typeof i2) => any
>x : new (x: typeof i2) => any
>i2 : new (x: any) => any
>x : new (x: any) => typeof x
var i2 = new i2(i2);
>i2 : new (x: any) => any
>new i2(i2) : new (x: any) => any
>i2 : new (x: any) => any
>i2 : new (x: any) => any
var j2: new <T extends typeof j2>(x: T) => T;
>j2 : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
>x : T
var j2 = new j2(j2);
>j2 : new <T extends any>(x: T) => T
>new j2(j2) : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
>k : { [n: number]: any; [s: string]: any; }
>n : number
>k : { [n: number]: any; [s: string]: any; }
>s : string
>k : { [n: number]: any; [s: string]: any; }
var k = k[0];
>k : { [n: number]: any; [s: string]: any; }
>k[0] : { [n: number]: any; [s: string]: any; }
>k : { [n: number]: any; [s: string]: any; }
>0 : 0
var k = k[''];
>k : { [n: number]: any; [s: string]: any; }
>k[''] : { [n: number]: any; [s: string]: any; }
>k : { [n: number]: any; [s: string]: any; }
>'' : ""
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
>hy1 : { x: typeof hy1; }[]
>x : { x: typeof hy1; }[]
>hy1 : { x: any[]; }[]
var hy1 = hy1[0].x;
>hy1 : { x: any[]; }[]
>hy1[0].x : { x: any[]; }[]
>hy1[0] : { x: any[]; }
>hy1 : { x: any[]; }[]
>0 : 0
>x : { x: any[]; }[]
var hy2: { x: Array<typeof hy2> };
>hy2 : { x: Array<typeof hy2>; }
>x : { x: Array<typeof hy2>; }[]
>hy2 : { x: any[]; }
var hy2 = hy2.x[0];
>hy2 : { x: any[]; }
>hy2.x[0] : { x: any[]; }
>hy2.x : { x: any[]; }[]
>hy2 : { x: any[]; }
>x : { x: any[]; }[]
>0 : 0
interface Foo2<T, U> { }
// This one should be an error because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
>hy3 : any
>hy3 : any
>x : any
>hy3 : any
var hy3: any;
>hy3 : any