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

Rename Omit #27

Closed
sindresorhus opened this issue Apr 16, 2019 · 16 comments · Fixed by #44
Closed

Rename Omit #27

sindresorhus opened this issue Apr 16, 2019 · 16 comments · Fixed by #44
Labels
help wanted Extra attention is needed

Comments

@sindresorhus
Copy link
Owner

We managed to convince the TS team to add Omit as a built-in type, unfortunately, they added a loose version, not what we suggested, and they insist on staying with it.

The great thing about user-land code is that we can fix their dumb decisions.

However, that does mean our Omit type will conflict with the native one... But I guess that gives us the opportunity to come up with a better name for it.

I never really found Omit that clear. How about ExcludeProperty or ExcludeKey? I prefer the former. Open to other suggestions.

@BendingBender
Copy link
Collaborator

I find ExcludeProperty very appealing.

@CvX
Copy link
Collaborator

CvX commented Apr 16, 2019

The another option is StrictOmit, to highlight both similarity to the built-in and its main difference. But I'm ok with any of suggested names.

@sindresorhus
Copy link
Owner Author

@CvX I don't like having to prefix types with Strict. They should IMHO be strict by default. In this case, it's not up to us, so I would rather have a different name.

@sindresorhus
Copy link
Owner Author

Alright. We'll go with ExcludeProperty. But let's defer doing anything until it's 100% certain that TS 3.5 will ship with a loose Omit type.

@sindresorhus
Copy link
Owner Author

Relevant discussion: microsoft/TypeScript#31205

@sindresorhus
Copy link
Owner Author

Since we're renaming this anyway, maybe we should name it ExcludeProperties and add support for excluding multiple properties?

@BendingBender
Copy link
Collaborator

As far as I understand the type, it will already exclude multiple properties when used with a union type:

Omit<SomeType, 'foo' | 'bar'>

will omit properties foo and bar.

@andyfleming
Copy link

While I wish they would have stayed consistent with what the community already understands as the behavior of Omit, I do actually like having an omit-key-if-exists AND a omit-key form of the type helper.

@andyfleming
Copy link

I think I like ExcludeKey over ExcludeProperty since it matches the language they use with syntax types like keyof.

@andyfleming
Copy link

I'm also not convinced we need a second word in the type name.

Something like Exclude, Remove, or Without could be viable.

@sindresorhus
Copy link
Owner Author

As far as I understand the type, it will already exclude multiple properties when used with a union type:

I did not realize that. We should definitely document that better.

@sindresorhus
Copy link
Owner Author

@andyfleming Yeah, I like your argument about consistency. But shouldn't it be ExcludeKeys since it supports multiple keys?

@andyfleming
Copy link

@sindresorhus I think the verbalized version of it makes sense as singular, specifically because of the union type.

let obj: ExcludeKey<ObjectType, "a" | "b">

Exclude key "a" or "b"

@andyfleming
Copy link

We may also want to consider if we should avoid using the word Exclude since it's already in typescript as a type helper.

@kainiedziela
Copy link
Contributor

How about reducing it to a single word 'Except'? Then it's readable, understandable and I believe has no conflicts with wording. Skip and Bypass are viable as well but I have to say - Omit is by far the most clear one.

let obj: Except<ObjectType, 'a' | 'b'>

@sindresorhus
Copy link
Owner Author

Alright. Let's go with Except.

@sindresorhus sindresorhus added the help wanted Extra attention is needed label Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants