Skip to content

Reverse type inference #3253

Answered by JacobWeisenburger
rChaoz asked this question in Q&A
Discussion options

You must be logged in to vote

Is this what you are looking for?

interface MyType {
    firstName: string
    lastName: string
    age: number
    whatever?: boolean
}

const myTypeSchema = z.object( {
    firstName: z.string(),
    lastName: z.string(),
    age: z.number(),
    extra: z.number(),
} ) satisfies z.Schema<MyType>

If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏
https://github.com/sponsors/JacobWeisenburger

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rChaoz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3244 on February 17, 2024 16:44.