From 35f1fcbe85f2ff2fd5aa164ffd892ccd88689d64 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 9 Feb 2018 13:02:21 -0800 Subject: [PATCH] Add tests --- .../types/conditional/conditionalTypes1.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/cases/conformance/types/conditional/conditionalTypes1.ts b/tests/cases/conformance/types/conditional/conditionalTypes1.ts index 93069138b36..8efd5f3d3c1 100644 --- a/tests/cases/conformance/types/conditional/conditionalTypes1.ts +++ b/tests/cases/conformance/types/conditional/conditionalTypes1.ts @@ -31,6 +31,13 @@ function f3(x: Partial[keyof T], y: NonNullable[keyof T]>) { y = x; // Error } +function f4(x: T["x"], y: NonNullable) { + x = y; + y = x; // Error + let s1: string = x; // Error + let s2: string = y; +} + type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean }; type T10 = Diff; // { k: "c", c: boolean } @@ -42,8 +49,8 @@ type T13 = Filter; // { k: "a", a: number } | type T14 = Diff; // Options type T15 = Filter; // never -declare function f4(p: K): Filter; -let x0 = f4("a"); // { k: "a", a: number } +declare function f5(p: K): Filter; +let x0 = f5("a"); // { k: "a", a: number } type OptionsOfKind = Filter; @@ -256,3 +263,20 @@ function f33() { var z: T1; var z: T2; } + +// Repro from #21823 + +type T90 = T extends 0 ? 0 : () => 0; +type T91 = T extends 0 ? 0 : () => 0; +const f40 = (a: T90): T91 => a; +const f41 = (a: T91): T90 => a; + +type T92 = T extends () => 0 ? () => 1 : () => 2; +type T93 = T extends () => 0 ? () => 1 : () => 2; +const f42 = (a: T92): T93 => a; +const f43 = (a: T93): T92 => a; + +type T94 = T extends string ? true : 42; +type T95 = T extends string ? boolean : number; +const f44 = (value: T94): T95 => value; +const f45 = (value: T95): T94 => value; // Error