I want to parse a JSON from the server and convert it to my model.
Of course, I can use JSON.parse
in combination with a model interface, but the problem is that I should also check if the keys of the JSON actually exist and if they match the actual types because, of course, one can't fully trust that what is received as always correct.
How I would go about this is by creating a function that tells if the object is an instance of that particular model where each key would be checked against undefined and also verify its typeof
.
How do you usually handle the creation of models in TypeScript?
Thanks!