-
Notifications
You must be signed in to change notification settings - Fork 14
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
Provide a no-parameter creator when type is "empty" #15
Conversation
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.
This will be a great improvement 👍
{ [key: string]: { _: 'F' } } | ||
)[L]['_'] | ||
|
||
export type ObjectHasKeys<O> = StringContains<keyof O, keyof O> |
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.
How about just using typelevel-ts
for this machinery? There's really no downside since it's purely a static dependency.
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.
This is actually different from typelevel-ts
's implementation of StringContains
, which fails when applied to the keys of a primitive like number
or boolean
.
I can look into trying to work around that failure, or perhaps getting a PR into typelevel-ts
, since it would definitely be preferable to depend on an external library for all of this.
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.
I see. Well, no need to go into contortions for it.
Hm, maybe it would be better to only apply this trick when the union's value type is precisely const { value } = unionize({ foo: ofType<null>() }, 'tag', 'value').foo() The type system will infer |
Also could you add a test for this? |
Closing this in favor of an implementation based on conditional types, since they'll provide far more flexibility for introducing type-dependent modifications of the unionize API. |
For "empty" types (
{}
,void
,null
), theCreator
function no longer accepts an argument.The spec for whether a type is empty is as follows: