Skip to content
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

Open
justin0mcateer opened this issue Sep 29, 2024 · 1 comment
Open

Allow 'overwriting' fields when using 'merge' on schemas #95

justin0mcateer opened this issue Sep 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@justin0mcateer
Copy link

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.

@DZakh
Copy link
Owner

DZakh commented Sep 30, 2024

I'll investigate.

@DZakh DZakh added the enhancement New feature or request label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants