Want help creating custom type inference similar to Zod

290 views Asked by At

I am working on a library in typescript that works like ZOD, but where each object has built-in methods to persist itself in a database.

So far, I have successfully made functions that check input datatypes at runtime, but I would like to add a Zod-style type inference feature.

Unfortunately, I don't know where to start. I looked at the source code of Zod on github and found that it uses conditional types, but I still can't understand how an object instantiated at runtime (z.object) can be inferred into a compile-time type.

Any help appreciated.

0

There are 0 answers