4 ms·
> I'm disappointed that it still doesn't incorporate a tool for one common case, runtime type checking. Node.js REST servers receive a lot of JSON objects and i
by throw_m239339 6y ago
> I'm disappointed that it still doesn't incorporate a tool for one common case, runtime type checking. Node.js REST servers receive a lot of JSON objects and it would be nice to automatically check that they actually follow type.
You are using the wrong tool for the job then. There are json-schema libraries made for that purpose. It has absolutely nothing to do with Typescript which is just basically a static type analyser, not a language with a runtime, since it does absolutely nothing at runtime.
- xsmasher 6y agojson-schema is hideous compared to TS type definitions, though.
- throw_m239339 6y agojson-schema works at runtime, that's what you want to validate your serialized messages. None of that stuff is related to typescript. Typescript is a static code analyser, nothing more. It doesn't do anything at runtime.
- xsmasher 6y agoI see the utility of json-schema, I just wish the schemas were beautiful and succinct like TS type definitions are. I know one is runtime and one is compile-time, but they both allow you to specify the "shape" of a particular JSON object and verify an example against it.