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

use DeepPartial for acceptable DataType into ValidatedForm #318

Merged
merged 1 commit into from
Aug 14, 2023
Merged

use DeepPartial for acceptable DataType into ValidatedForm #318

merged 1 commit into from
Aug 14, 2023

Conversation

Alex-Yakubovsky
Copy link
Contributor

@Alex-Yakubovsky Alex-Yakubovsky commented Aug 12, 2023

closes #313

  • Adds a DeepPartial type
  • Uses DeepPartial for default types, allowing users to pre-set set a subset of deeply nested fields (useful for arrays and nested types)
// example todo validator
const validator = withZod(
  z.array(
    z.object({
      title: z.string()
      dueDate: z.string()
    })
  )
);

...

<ValidatedForm validator={validator} defaultValues={[{ title: 'my todo' }]}> // Without a `DeepPartial` this causes a type error
   // ...
</ValidatedForm>
  • Updates DataType to extend { [fieldName: string]: any } for ValidatedForm
    • My understanding is that is a requirement anyway, but without explicitly specifying the constraint DeepPartial will cause a type error on the InternalFormContextValue. This is because DeepPartial<DataType> will unpack as DataType | { P in keyof DataType]?: DeepPartial<DataType[P]> | undefined. Since DataType could be anything, it isn't assignable to the expected { [fieldName: string]: any; } for defaultValuesProp

@vercel
Copy link

vercel bot commented Aug 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
remix-validated-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2023 5:15pm

@airjp73
Copy link
Owner

airjp73 commented Aug 14, 2023

Thanks!

@airjp73 airjp73 merged commit acee27f into airjp73:main Aug 14, 2023
2 checks passed
@Alex-Yakubovsky Alex-Yakubovsky deleted the use-deep-partial-for-validated-form-data-type branch August 15, 2023 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Use a deep partial TS type for defaultValues prop
2 participants