-
-
Notifications
You must be signed in to change notification settings - Fork 569
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 SingleKey and IfEmptyObject #849
Conversation
I think it should be named |
source/single-key.d.ts
Outdated
*/ | ||
|
||
// export type SingleKey<ObjectType> = | ||
// IsUnion<keyof ObjectType> extends true ? never : {} extends ObjectType ? never : ObjectType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops I thought I removed them all
source/single-key.d.ts
Outdated
``` | ||
|
||
@category Object | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*/ | |
*/ |
source/single-key.d.ts
Outdated
}, | ||
values: [1, 2] | ||
}); | ||
// Compilation error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the actual compilation here.
source/single-key.d.ts
Outdated
operation: { | ||
name: 'add' | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the example simple by not using a nested property here.
Agreed, I just renamed it and fixed the documentation |
Thanks :) |
Thanks for doing this, @ash-zzz! Should this work for types where the keys are unrestricted? If not, I'm not sure it satisfies my original request from #813, which was to declare an object type that requires exactly one key without restricting the key itself to any specific string or union of strings. I tried |
Closes #813
I also added IfEmptyObject since that was a missing guard type that I needed to use for this