Add regression tests

This commit is contained in:
Anders Hejlsberg 2018-02-14 09:20:13 -08:00
parent 3a61f638ba
commit 3de1cd6f2d

View file

@ -287,3 +287,33 @@ function f50() {
type A = Omit<{ a: void; b: never; }>; // 'a'
type B = Omit2<{ a: void; b: never; }>; // 'a'
}
// Repro from #21862
type OldDiff<T extends string, U extends string> = (
& { [P in T]: P; }
& { [P in U]: never; }
& { [x: string]: never; }
)[T];
type NewDiff<T, U> = T extends U ? never : T;
interface A {
a: 'a';
}
interface B1 extends A {
b: 'b';
c: OldDiff<keyof this, keyof A>;
}
interface B2 extends A {
b: 'b';
c: NewDiff<keyof this, keyof A>;
}
type c1 = B1['c']; // 'c' | 'b'
type c2 = B2['c']; // 'c' | 'b'
// Repro from #21929
type NonFooKeys1<T extends object> = OldDiff<keyof T, 'foo'>;
type NonFooKeys2<T extends object> = Exclude<keyof T, 'foo'>;
type Test1 = NonFooKeys1<{foo: 1, bar: 2, baz: 3}>; // "bar" | "baz"
type Test2 = NonFooKeys2<{foo: 1, bar: 2, baz: 3}>; // "bar" | "baz"