DEV Community

Cover image for Fastest Way to Auto Generate Types for Typescript and Input validation
DX Knight
DX Knight

Posted on • Updated on

Fastest Way to Auto Generate Types for Typescript and Input validation

Short description

Writing types for API's especially giant JSON's are frustrating especially when it comes to input validation.

solution:

Just paste your json inside app.quicktype.io or it's vscode

Image description

Now you can paste that type into transform.tools/typescript-to-zod to generate the corresponding zod schema for input validation:

Image description

Note 🏅 For Practical step by step example check this 4min youtube video:

Video - Skip Writing types manually

Github Project

Top comments (5)

Collapse
 
fbolaji profile image
Francis.B

A schema from backend can speed up generating types

Collapse
 
seyyedkhandon profile image
DX Knight

Yeah, but Most of the time schema for 3rd party api's are not available.

Collapse
 
omar_karim_192f75c9c75bd9 profile image
Omar Karim

Amature hour

Collapse
 
yeudaby profile image
Yeuda By

And what about nullable types? That's why I prefer to stick to the server-side scheme

Collapse
 
seyyedkhandon profile image
DX Knight

It supports that too. bu what do you mean about server side scheme? can you please explain more