Created
September 21, 2023 12:53
-
-
Save renatoargh/d2a03ab44659d4a0e1857868e45181e4 to your computer and use it in GitHub Desktop.
Zod Sorcery from https://stackoverflow.com/questions/76123184/how-to-infer-type-from-a-schema-generated-by-a-generic-function-in-zod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Leaf<T> = z.infer<ReturnType<typeof LeafSchema<z.ZodType<T>>>> | |
type NumberLeaf = Leaf<number> | |
const getLeafValue = <T>(leaf: Leaf<T>) => leaf.value; | |
const test = { 'value': 123 }; | |
const val = getLeafValue(test); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment