|
|
|
|
|
by hellcow
1087 days ago
|
|
I’ve used zod and every other schema validator available for this. Some problems: 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. |
|
2. Use let and modify your types as new ones become available - union them with a new object that contains the new property you need
3. How often are you making recursive types?
I agree that all of this could be made easier, but zod is the best we have and great for most normal usage. The reason TS doesn't want to make this available at runtime is that it means so many changes they make will become breaking changes. Perhaps one day when there's less development on TS we'll see this get added