Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Fixed input type inference #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chungweileong94
Copy link

@chungweileong94 chungweileong94 commented May 5, 2023

The current input type inference doesn't support zod transform, we should use z.input<...> to infer the zod input type instead.

Reference: https://zod.dev/?id=type-inference

@vercel
Copy link

vercel bot commented May 5, 2023

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

Name Status Preview Comments Updated (UTC)
zact-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2023 2:43pm

@pedro757
Copy link

pedro757 commented May 5, 2023

What? I don't understand this pr..

@chungweileong94
Copy link
Author

chungweileong94 commented May 6, 2023

What? I don't understand this pr..

Basically, if you specify the input schema as z.string().datetime().transform(v => new Date(v)), zod will expect a string then convert to date object for you. However, if you use z.infer to infer the input type, TS will force you to pass date object as input, which is incorrect.

@Quatton
Copy link

Quatton commented May 6, 2023

That is indeed important. Thank you for noticing that.

@chris-allen
Copy link

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants