-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
fix: input and output types #243
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This seems like a reasonable change, but I'll admit I don't fully understand the use-cases behind tracking the input type. We might want to broaden the type though. This can be used when URLSearchParams, too, and I don't want to accidently forbid that usage. Technically we can use any Iterable that returns entries. |
I broadened the type to this: {
[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
entries(): IterableIterator<[string, FormDataEntryValue]>;
}
The use case is that in tRPC we infer the type that users need to pass to their API using Zod's t.procedure
.input(
zfd.formData({
name: zfd.text(),
})
)
.mutation(({ input }) => {
console.log(input);
}); so on the client users can know exactly what they need to pass to this API function: const formMutation = trpc.form.useMutation()
// type here must be FormData, automatically inferred from the server using `z.input`
formMutation.mutate(new FormData(e.currentTarget))
formData.mutate('hello') // this gives a TS type error |
Fantastic. Thanks for the detailed response. 😊 This looks good -- I'll publish as a major version bump. |
Published in v2.0.0 |
is now of type
FormData
instead of{ name: string }
.form
is still typed as{ name: string }
here.I need this type to be correct so input types are inferred accurately for a form data integration I'm working on for tRPC.