Test:inference to self-referential mapped type

From a self-referential type.
This commit is contained in:
Nathan Shively-Sanders 2017-11-30 09:40:43 -08:00
parent b1316e589e
commit 1068ee105d
4 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,10 @@
//// [mappedTypeRecursiveInference.ts]
interface A { a: A }
declare let a: A;
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
declare function foo<T>(deep: Deep<T>): T;
const out = foo(a);
//// [mappedTypeRecursiveInference.js]
var out = foo(a);

View file

@ -0,0 +1,32 @@
=== tests/cases/compiler/mappedTypeRecursiveInference.ts ===
interface A { a: A }
>A : Symbol(A, Decl(mappedTypeRecursiveInference.ts, 0, 0))
>a : Symbol(A.a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>A : Symbol(A, Decl(mappedTypeRecursiveInference.ts, 0, 0))
declare let a: A;
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 1, 11))
>A : Symbol(A, Decl(mappedTypeRecursiveInference.ts, 0, 0))
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
>Deep : Symbol(Deep, Decl(mappedTypeRecursiveInference.ts, 1, 17))
>T : Symbol(T, Decl(mappedTypeRecursiveInference.ts, 2, 10))
>K : Symbol(K, Decl(mappedTypeRecursiveInference.ts, 2, 18))
>T : Symbol(T, Decl(mappedTypeRecursiveInference.ts, 2, 10))
>Deep : Symbol(Deep, Decl(mappedTypeRecursiveInference.ts, 1, 17))
>T : Symbol(T, Decl(mappedTypeRecursiveInference.ts, 2, 10))
>K : Symbol(K, Decl(mappedTypeRecursiveInference.ts, 2, 18))
declare function foo<T>(deep: Deep<T>): T;
>foo : Symbol(foo, Decl(mappedTypeRecursiveInference.ts, 2, 45))
>T : Symbol(T, Decl(mappedTypeRecursiveInference.ts, 3, 21))
>deep : Symbol(deep, Decl(mappedTypeRecursiveInference.ts, 3, 24))
>Deep : Symbol(Deep, Decl(mappedTypeRecursiveInference.ts, 1, 17))
>T : Symbol(T, Decl(mappedTypeRecursiveInference.ts, 3, 21))
>T : Symbol(T, Decl(mappedTypeRecursiveInference.ts, 3, 21))
const out = foo(a);
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
>foo : Symbol(foo, Decl(mappedTypeRecursiveInference.ts, 2, 45))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 1, 11))

View file

@ -0,0 +1,33 @@
=== tests/cases/compiler/mappedTypeRecursiveInference.ts ===
interface A { a: A }
>A : A
>a : A
>A : A
declare let a: A;
>a : A
>A : A
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
>Deep : Deep<T>
>T : T
>K : K
>T : T
>Deep : Deep<T>
>T : T
>K : K
declare function foo<T>(deep: Deep<T>): T;
>foo : <T>(deep: Deep<T>) => T
>T : T
>deep : Deep<T>
>Deep : Deep<T>
>T : T
>T : T
const out = foo(a);
>out : { a: {}; }
>foo(a) : { a: {}; }
>foo : <T>(deep: Deep<T>) => T
>a : A

View file

@ -0,0 +1,5 @@
interface A { a: A }
declare let a: A;
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
declare function foo<T>(deep: Deep<T>): T;
const out = foo(a);