-
Notifications
You must be signed in to change notification settings - Fork 7
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
Allow 'overwriting' fields when using 'merge' on schemas #95
Comments
I'll investigate. |
This would make porting over from Zod easier as it's Zod's behavior: https://zod.dev/?id=merge |
It shouldn't be difficult if we require them to have the same type. |
Same type wouldn't generalize well right? Like: const A = S.schema({ kind: 'a' })
const B = S.schema({ kind: 'b' })
const C = S.merge(A, B) Not sure if that's important |
In this cases these are Literal("a") and Literal("b") which won't merge |
Humm yeah and then you’d need something like Pick and Omit. And rescript kinda struggles with that as seen with #96 |
Maybe for v11, I didn't really have a use case for this myself, since in ReScript you design data differently |
The relatively new 'merge' function is very helpful. Thanks for adding that.
We often use the 'merge' function to produce more specific versions of some base type. In this case, it's helpful to be able to narrow certain types in the result of the intersection/merge.
As an example:
type Base = {
type: 'foo' | 'bar',
name: string,
}
type Foo = {
type: 'foo',
name: string,
fooCount: number,
}
type Bar = {
type: 'bar',
name: string,
barSize: 'small' | 'large',
}
Currently, if a field exists in both types provided to 'merge', it throws an error that 'type' is already defined. In Zod, the Schema on the right overrides the Schema on the left. This also allows for creating some type of derived schema where one or two properties are different.
The text was updated successfully, but these errors were encountered: