|
|
|
|
|
by mnahkies
1093 days ago
|
|
You should take a look at https://zod.dev/ if you haven't already - it's a library for runtime parsing that works really well for your use case. Types are inferred from the schema though personally I like to handwrite types as well to sense check that the schema describes the type I think it does |
|
1. Types are not written in typescript anymore. Or you have to define them twice and manually ensure they match. ReturnType<typeof MyType> pollutes the codebase.
2. Types have to be defined in order, since they’re now consts. If you have a lot of types which embed other types, good luck determining that order by hand.
3. Recursive types need to be treated specially because a const variable can’t reference itself without some lazy evaluation mechanism.
TS could solve all of this by baking this into the language.