Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude<T, U> type not working like Diff<T, U> #21929

Closed
yortus opened this issue Feb 14, 2018 · 5 comments
Closed

Exclude<T, U> type not working like Diff<T, U> #21929

yortus opened this issue Feb 14, 2018 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@yortus
Copy link
Contributor

yortus commented Feb 14, 2018

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:

@DanielRosenwasser
Copy link
Member

Of note, I'm getting some strange quick info. When defined as

type NonFooKeys<T> = Exclude<keyof T, 'foo'>;

I get

type NonFooKeys<T> = keyof T

@jack-williams
Copy link
Collaborator

Is this related to #21664 ? Exclude works when used directly for me.

type BarBaz = Exclude<keyof { foo: 1, bar: 2, baz: 3 }, 'foo'> // BarBaz = "bar" | "baz"

@falsandtru
Copy link
Contributor

related #21862.

@ahejlsberg
Copy link
Member

Duplicate of #21862.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Feb 14, 2018
@KiaraGrouwstra
Copy link
Contributor

The other issue is marked fixed now.

@yortus yortus closed this as completed Feb 16, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants