-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Description
When using Partial as a value type the calling the constructors with any object type checks but it should not. For example the following should not type check
type T = { field: string }
const U = unionize({
PartialT: ofType<Partial<T>>(),
})
// This should fail
const u = U.PartialT({ foo: true })
const u2 = U.PartialT(true)The underlying problems seems to be that the constraint {} extends UnTagged<Partial<T>, 'tag'> does not hold. If we look at the definition of Creators we see that this results in the constructor accepting an argument of type undefined | {} which seems wrong.
export type Creators<Record, TaggedRecord, TagProp extends string> = {
[T in keyof Record]: {} extends UnTagged<Record[T], TagProp>
? ((value?: {}) => TaggedRecord[keyof TaggedRecord])
: ((value: UnTagged<Record[T], TagProp>) => TaggedRecord[keyof TaggedRecord])
}I’m not sure what the solution would be but would be happy to create a PR if somebody has a suggestion.
Metadata
Metadata
Assignees
Labels
No labels