From 19e07eaea63210d1afc8045adab72f418341edc3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 4 Mar 2018 16:49:06 -0800 Subject: [PATCH] Add tests --- .../types/conditional/inferTypes1.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/cases/conformance/types/conditional/inferTypes1.ts b/tests/cases/conformance/types/conditional/inferTypes1.ts index 1defacc08cc..8907cf79d91 100644 --- a/tests/cases/conformance/types/conditional/inferTypes1.ts +++ b/tests/cases/conformance/types/conditional/inferTypes1.ts @@ -90,6 +90,15 @@ type T76 = { x: T }; type T77 = T extends T76 ? T76 : never; type T78 = T extends T76 ? T76 : never; +type Foo = [T, U]; +type Bar = T extends Foo ? Foo : never; + +type T90 = Bar<[string, string]>; // [string, string] +type T91 = Bar<[string, "a"]>; // [string, "a"] +type T92 = Bar<[string, "a"] & { x: string }>; // [string, "a"] +type T93 = Bar<["a", string]>; // never +type T94 = Bar<[number, number]>; // never + // Example from #21496 type JsonifiedObject = { [K in keyof T]: Jsonified }; @@ -150,3 +159,11 @@ interface test { type T80 = MatchingKeys; type T81 = VoidKeys; + +// Repro from #22221 + +type MustBeString = T; +type EnsureIsString = T extends MustBeString ? U : never; + +type Test1 = EnsureIsString<"hello">; // "hello" +type Test2 = EnsureIsString<42>; // never