Skip to content

Is empty#19

Closed
garronej wants to merge 4 commits intomainfrom
is_empty
Closed

Is empty#19
garronej wants to merge 4 commits intomainfrom
is_empty

Conversation

@garronej
Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/IsEmpty.ts
@@ -0,0 +1 @@
export type IsEmpty<T> = [keyof T] extends [never] ? true : false;
Copy link
Copy Markdown
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
Copy Markdown
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.

2 participants