Type Mismatch in Update Mutation with Optional Fields
I’m running into a type mismatch issue when updating an account using a mutation. Simplified version of my setup:
schema.ts
accounts.ts
component
Error
Types of property 'name' are incompatible.• In the mutation, I’ve excluded the type field and allowed the remaining fields to be updated. • The handleUpdateAccount function uses Partial so only the fields that need updating are passed. • I suspect the issue is that the mutation expects all fields to be required, but I’m passing optionals. Is there a proper way to define the mutation to accept optional fields without manually marking each field as optional? Should I adjust the schema or is there a better solution to handle partial updates?
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
2 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I resolved the issue using validator utilities like partial, pick, and omit to match the TypeScript type utilities.
https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/README.md#validator-utilities
GitHub
convex-helpers/packages/convex-helpers/README.md at main · get-conv...
A collection of useful code to complement the official packages. - get-convex/convex-helpers