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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is empty #19

Closed
wants to merge 4 commits into from
Closed

Is empty #19

wants to merge 4 commits into from

Conversation

garronej
Copy link
Owner

No description provided.

@@ -0,0 +1 @@
export type IsEmpty<T> = [keyof T] extends [never] ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I have seen that one somewhere else ;)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @danieldietrich,
I didn't though you'd see that.

In fact, I am just testing pre-releasing and Deno an NPM for a PR that I have going on.

I wouldn't just steal your utility without asking you first :)

About actually including IsEmpty<> I am divided.
On one and it's something that I need all the time, to make sure that I didn't forget to deconstruct any properties of an object, it is super handy.

I often do

const {foo, bar, baz, ...rest }= obj

assert<Equals<keyof typeof rest, never>>();

I don't really need a utility but it does look cryptic to my colleagues, the following would make the assert statement much more transparent:

const {foo, bar, baz, ...rest }= obj

assert<IsEmpty<typeof rest>>();

So I think it might be worth including.
I also think I should maybe rearrange the documentation and gather under a unique section all helper types that are meant to be used with assert<>()

Anyway, I'll close this for now but to be continued. :)

PS: I have opened an issue that I think if implemented properly could be game changing.
#18 I'd love to know what you think.

Best regards,

@garronej garronej closed this Oct 11, 2022
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.

None yet

2 participants