From 95bb156a3e3064ccc6c0a5fc5a92e652c84a7872 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 2 Mar 2018 09:26:52 -0800 Subject: [PATCH] Add tests --- .../types/keyof/keyofIntersection.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/cases/conformance/types/keyof/keyofIntersection.ts diff --git a/tests/cases/conformance/types/keyof/keyofIntersection.ts b/tests/cases/conformance/types/keyof/keyofIntersection.ts new file mode 100644 index 00000000000..f570a873242 --- /dev/null +++ b/tests/cases/conformance/types/keyof/keyofIntersection.ts @@ -0,0 +1,29 @@ +// @strict: true +// @declaration: true + +type A = { a: string }; +type B = { b: string }; + +type T01 = keyof (A & B); // "a" | "b" +type T02 = keyof (T & B); // "b" | keyof T +type T03 = keyof (A & U); // "a" | keyof U +type T04 = keyof (T & U); // keyof T | keyof U +type T05 = T02; // "a" | "b" +type T06 = T03; // "a" | "b" +type T07 = T04; // "a" | "b" + +// Repros from #22291 + +type Example1 = keyof (Record & Record); +type Result1 = Example1<'x', 'y'>; // "x" | "y" + +type Result2 = keyof (Record<'x', any> & Record<'y', any>); // "x" | "y" + +type Example3 = keyof (Record); +type Result3 = Example3<'x' | 'y'>; // "x" | "y" + +type Example4 = (Record & Record); +type Result4 = keyof Example4<'x', 'y'>; // "x" | "y" + +type Example5 = keyof (T & U); +type Result5 = Example5, Record<'y', any>>; // "x" | "y"