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

Proposal: IfAny, IsAny, IsUnknown, etc #129

Closed
sindresorhus opened this issue Aug 21, 2020 · 6 comments · Fixed by #564
Closed

Proposal: IfAny, IsAny, IsUnknown, etc #129

sindresorhus opened this issue Aug 21, 2020 · 6 comments · Fixed by #564
Labels
help wanted Extra attention is needed type addition

Comments

@sindresorhus
Copy link
Owner

https://github.com/sindresorhus/type-fest/pull/127/files#r474306457

Thoughts?

@Milo123459
Copy link

@sindresorhus I think this would be very helpful.

@sindresorhus
Copy link
Owner Author

What would you use it for?

@Milo123459
Copy link

I have a new package I'm working on, which works with objects. This would help me manage things.

If this doesn't get added, I don't really mind, it's already an amazing library. Thanks @sindresorhus 👍

@sindresorhus
Copy link
Owner Author

Alright. This is PR welcome.

The submitter should make sure to follow https://github.com/sindresorhus/type-fest/blob/master/.github/contributing.md closely.

@sindresorhus sindresorhus added the help wanted Extra attention is needed label Sep 28, 2020
@sindresorhus
Copy link
Owner Author

If anyone wants to work on this, see the initial attempt in #505

Instead of IfAny, we could potentially do what's done in #544 Feedback wanted on that way of handling it.

@tommy-mitchell
Copy link
Contributor

tommy-mitchell commented Mar 2, 2023

I've started working on this, but I'm struggling to think of use cases for these beyond being helpers in other types.

I also started by making both an IsAny and an IfAny in is-if-any.d.ts (etc.), but I found that unional/type-plus#201 combined them like so:1

type IsAny<T, TypeIfAny = true, TypeIfNotAny = false> = 0 extends 1 & T ? TypeIfAny : TypeIfNotAny;

IsAny<any> //=> true
IsAny<number> //=> false
IsAny<any, number, string> //=> number

I kind of like that IsAny and IfAny are more explicit in what they do, but the succinctness of this method is nice. Thoughts?

Footnotes

  1. Really, it was IsNever, but it's the same difference.

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 type addition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants