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

Add Omit<T,K> and Diff<T,U> to lib.d.ts #19569

Closed
Pajn opened this issue Oct 30, 2017 · 9 comments
Closed

Add Omit<T,K> and Diff<T,U> to lib.d.ts #19569

Pajn opened this issue Oct 30, 2017 · 9 comments
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@Pajn
Copy link

Pajn commented Oct 30, 2017

As spread and rest types is taking time I usually have to copy these types in projects. They solve the primary use case for spread/rest types and works today. I think they should fit right in next to Pick and Partial.
And even when (if?) spread and rest types is merged these would still arguably have some value.

export type Diff<T extends string, U extends string> = ({[P in T]: P} &
  {[P in U]: never} & {[x: string]: never})[T]
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>
@kitsonk
Copy link
Contributor

kitsonk commented Oct 30, 2017

Awesome type operators... even if it doesn't get included thanks for the ideas.

@Pajn
Copy link
Author

Pajn commented Oct 30, 2017

Oh, maybe I should have made it clear. These are not mine, I found them buried deep in a conversation once but I managed to find them again here: #12215 (comment)

It also have this great type which I had totally forgotten as it's hard to find that specific comment via Google.

type Overwrite<T, U> = { [P in Diff<keyof T, keyof U>]: T[P] } & U;

@NN---
Copy link

NN--- commented Oct 30, 2017

Please also Required type from discussion of #15012

@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2017

As i noted in the Required one, i think we need a type operator here instead.

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Oct 30, 2017
@NN---
Copy link

NN--- commented Oct 30, 2017

@mhegazy Without any doubt it will be a great solution, but if it won't go in the foreseen TS version, then Required can be a nice workaround meanwhile.

@ahejlsberg
Copy link
Member

See #21316.

@Pajn
Copy link
Author

Pajn commented Jan 22, 2018

@ahejlsberg Conditional types would be awesome and solve many problems but this issue is just about integrating types already writeable (and already written in many @types/ packages) in a default .lib.d.ts.

@ahejlsberg
Copy link
Member

@Pajn Understood. The link was merely to point out there's now a better way to implement these types.

@Pajn
Copy link
Author

Pajn commented Jan 23, 2018

Ah, yes that's possible. I just wanted to be clear that I don't think this issue should be closed by #21316. I don't want to sound negative though, I'm super excited by conditional types in itself!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants