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

Fixed input type inference#19

Open
chungweileong94 wants to merge 1 commit into
pingdotgg:mainfrom
chungweileong94:main
Open

Fixed input type inference#19
chungweileong94 wants to merge 1 commit into
pingdotgg:mainfrom
chungweileong94:main

Conversation

@chungweileong94

@chungweileong94 chungweileong94 commented May 5, 2023

Copy link
Copy Markdown

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

vercel Bot commented May 5, 2023

Copy link
Copy Markdown

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

pedro757 commented May 5, 2023

Copy link
Copy Markdown

What? I don't understand this pr..

@chungweileong94

chungweileong94 commented May 6, 2023

Copy link
Copy Markdown
Author

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

Quatton commented May 6, 2023

Copy link
Copy Markdown

That is indeed important. Thank you for noticing that.

@chris-allen

Copy link
Copy Markdown

👍

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.

4 participants