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

DeepPartial Objects for SuperValidate #449

Open
CordlessWool opened this issue Jul 11, 2024 · 3 comments
Open

DeepPartial Objects for SuperValidate #449

CordlessWool opened this issue Jul 11, 2024 · 3 comments
Labels
enhancement New feature or request later May be worked on in the future.
Milestone

Comments

@CordlessWool
Copy link

Is your feature request related to a problem? Please describe.
Currently SuperValidate accepts Partial<In>, but we have a nested object structure and want to set default values in these sub objects.

Describe the solution you'd like
I know there is no default type for DeepPartial, but it would be nice to use DeepPartial<In> instead of just Partial<In>.

type DeepPartial<T> = T extends object ? {
    [P in keyof T]?: DeepPartial<T[P]>;
} : T;

Additional context
Currently we work around with a type cast like

import { superValidate, InferIn } from 'sveltekit-superform';

superValidate({
  nested: {
    some: 'data'
  } as Partial<InferIn<TypeOfObject>>
});
@CordlessWool CordlessWool added the enhancement New feature or request label Jul 11, 2024
@ciscoheat
Copy link
Owner

Good idea, will add to the next release if everything seems to work!

@ciscoheat
Copy link
Owner

It's a bit unfortunate, but since the default value of an array is an empty array, it won't traverse into arrays in the same way as objects. Changing the behavior would probably break some schemas (unions in arrays especially), and also require a bit of rewrite for the default value mapping, so I'm hesitant to add it to version 2.

I'll put it up on the v3 milestone for the time being, sorry.

@ciscoheat ciscoheat added this to the v3 milestone Jul 29, 2024
@ciscoheat ciscoheat added the later May be worked on in the future. label Jul 29, 2024
@ciscoheat
Copy link
Owner

Another example of when DeepPartial is useful: https://www.sveltelab.dev/fharhjf6zn96b9u?files=.%2Fsrc%2Froutes%2F%2Bpage.svelte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request later May be worked on in the future.
Projects
None yet
Development

No branches or pull requests

2 participants