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 ExtendsOr, ExtendsAnd, and ExtendsThenElse types #247

Closed
wants to merge 1 commit into from

Conversation

tmillr
Copy link

@tmillr tmillr commented Aug 11, 2021

A few basic utility types that act as || and && shorthands.

The third type is simply an if/then/else conditional which simply mirrors the behavior of typescript's extends ternary conditional expression (yeah I know not very useful but it allows for alternative syntax/style).

These utilities could also have other names such as:
ExtendsOr -> Or
ExtendsAnd -> And
ExtendsThenElse -> Cond or Condition or Conditional or Ternary etc.
...but I thought these names were ok.

These are all simple utilities, so how they work should be rather easy to figure out, although I did try to provide some examples (including an example that reflects a problem that originally inspired this idea having to do with Parameters<> erroring if it is not sure that it is receiving a Function).

@sindresorhus
Copy link
Owner

@Tyler1205 If you have time, it would be great if you could help review some of the other open pull requests. 🙏

@sindresorhus
Copy link
Owner

sindresorhus commented Sep 5, 2021

I'm a little bit conflicted about this. It tries to simplify code with utilities, but we also have to learn the utilities. When I person reading the code sees ExtendsOr, they need to look it up, but when using extends directly, they don't need to do that.

@papb
Copy link
Contributor

papb commented Jan 19, 2022

I am not sure either. I have also needed these helpers in the past in a few situations, but I just defined them myself so anyone reading my code will be able to understand without having to look it up.

@sindresorhus
Copy link
Owner

I have decided to decline this as the benefits are not worth the learnability overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants