24 ms·
How does one validate typescript models at runtime? I have seen combinations of JSON schema and validator libraries but I'd love to do it using typescript's typ
by sadlion 9y ago
How does one validate typescript models at runtime? I have seen combinations of JSON schema and validator libraries but I'd love to do it using typescript's type system. From my understanding, it doesn't work because of type erasure.
- ng12 9y agoAFAIK there's no good solution. That's why it works best when your back end is using Typescript as well -- your route returns the same interface the client is expecting.
- STRiDEX 9y agoYou don't. You'd have to use something like https://github.com/hapijs/joi https://github.com/hapijs/joi
- gcanti 9y agoThis is a TypeScript compatible runtime type system for IO validation https://github.com/gcanti/io-ts https://github.com/gcanti/io-ts