3 ms·
Sure, so anytime you read JSON from a file or receive it from a network call, somewhere in the stack you're running JSON.parse() on it to turn the JSON string i
by joshAg 5y ago
Sure, so anytime you read JSON from a file or receive it from a network call, somewhere in the stack you're running JSON.parse() on it to turn the JSON string into the javascript object/primitive (or when you pull in data from a db). What happens if that object isn't what you think it should be?
So like, if you've got an endpoint that says it returns
interface Foo {
baz: string
bar: number
}
What happens if the endpoint actually sends you
'{"bar":"23"}'
? How do you check to make sure the 'unverified' data is actually what you think it is?
Or if the db schema has a nullable column but the typescript type for some reason isn't nullable/optional? Or worse, the db query isn't pulling the fields it should be (eg the db schema changed but the typescript definition didn't).