-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Omit
as a known interface
#30455
Comments
Duplicate of #19569? |
Not really? That was back when there was only a hairy mapped-type based definition of |
Eventually that issue was closed after conditional types were added. @ahejlsberg made #21847 and said:
|
@nmain My 2¢, trivial for some magic for others, I would argue all build-in mapped and conditional types are trivial to write but that does not make them any less useful. Having a common set of types makes code easier to understand across projects. |
I personally use |
Totally agree, I end up declaring that |
I've used
That's not the same; and it's not even close. |
How so? Isn't it better to explain your train of thought when you say someone's wrong?... |
Sorry, you're right -- and my thoughts were wrong anyway. I would even say that omit is far more difficult than record! What I should have said is that it's better to compare |
The docs' reasoning about this is:
I'm not so sure about the triviality of it, especially for new TS devs, but IMHO this isn't a good reason for not including Omit, to me it feels like saying that if I have this code: return collection.map ( item => item.foo () ); I don't really need const result = [];
collection.forEach ( item => result.push ( item.foo () ) );
return result; I mean yeah, it's trivial, but am I supposed to write such ugly code every time or am I supposed to redefine |
This is now 3.5-bound! 🚀 You can try it out with our next nightly release. |
For those curious how the |
The naming of this is rather unfortunate. I mean to say, what exactly is the difference between the words "Omit" and "Exclude"? They are essentially synonyms with a minor nuance. The definition we have used is /**
* Exclude from T those types that are assignable to U
*/
type Exclude<T, U> = T extends U ? never : T;
/**
* From T remove the properties K
* E.g. ExcludeProperty<{ a: number, b: string }, 'b'> => { a: number }
*/
type ExcludeProperty<T, K extends keyof T> = Pick<T, Exclude<StringKeyOf<T>, K>>; |
For everyone watching this issue, note that the |
Search Terms
Omit
Suggestion
Add the following type to lib.d.ts:
More
Origin : #12215 (comment)
From : https://github.com/sindresorhus/type-fest/blob/0226ef2092ee2b07a8714c832d106da659877a8f/index.d.ts#L75
Please open new issues on TypeScript about making it built-in.
. I searched but couldn't find an issue, so here it is 🌹Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: