Skip to content
Prev Previous commit
Next Next commit
Add more tests
  • Loading branch information
ahejlsberg committed Aug 16, 2020
commit 199d568785a48a37031c68bf252d1027cb4e5abb
28 changes: 28 additions & 0 deletions tests/cases/compiler/recursiveConditionalTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @strict: true
// @declaration: true
// @target: esnext

// Awaiting promises

Expand Down Expand Up @@ -57,6 +58,33 @@ declare function f23<T>(t: TupleOf<T, 3>): T;

f23(['a', 'b', 'c']); // string

// Inference to recursive type

interface Box<T> { value: T };
type RecBox<T> = T | Box<RecBox<T>>;
type InfBox<T> = Box<InfBox<T>>;

declare function unbox<T>(box: RecBox<T>): T

type T1 = Box<string>;
type T2 = Box<T1>;
type T3 = Box<T2>;
type T4 = Box<T3>;
type T5 = Box<T4>;
type T6 = Box<T5>;

declare let b1: Box<Box<Box<Box<Box<Box<string>>>>>>;
declare let b2: T6;
declare let b3: InfBox<string>;
declare let b4: { value: { value: { value: typeof b4 }}};

unbox(b1); // string
unbox(b2); // string
unbox(b3); // InfBox<string>
unbox({ value: { value: { value: { value: { value: { value: 5 }}}}}}); // number
unbox(b4); // { value: { value: typeof b4 }}
unbox({ value: { value: { get value() { return this; } }}}); // { readonly value: ... }

// Inference from nested instantiations of same generic types

type Box1<T> = { value: T };
Expand Down