Closed
Description
TypeScript Version: 2.8.0-dev.20180213
Search Terms:
- Exclude
- Diff
Code
// Old 'Diff' type, superseded since #21847 by new 'Exclude' builtin type
type Diff<T extends string, U extends string>
= ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
type NonFooKeys1<T extends object> = Diff<keyof T, 'foo'>; // remove 'foo' using Diff
type NonFooKeys2<T extends object> = Exclude<keyof T, 'foo'>; // remove 'foo' using Exclude
type Test1 = NonFooKeys1<{foo: 1, bar: 2, baz: 3}>; // Test1 is "bar" | "baz"
type Test2 = NonFooKeys2<{foo: 1, bar: 2, baz: 3}>; // Test2 is "foo" | "bar" | "baz"
Expected behavior:
Test2
should be "bar" | "baz"
, the same as Test1
.
Actual behavior:
The key "foo"
was not removed from keyof T
when using the Exclude
builtin type.
Related Issues: