3 ms·
There are libraries that do type-safe schema validation (an article I found in a quick Google is linked below). That you can do something so sophisticated is a
by curtisf 6y ago
There are libraries that do type-safe schema validation (an article I found in a quick Google is linked below).
That you can do something so sophisticated is a testament to TypeScript's type system.
However, if you were writing JavaScript, I think it's (unfortunately) uncommon to have this kind of proactive validation. So, for people writing TypeScript as "JavaScript + types" (which is a perfectly fine way to use it), they would just use a type assertion, which is just writing down the assumption that the JavaScript programmer makes when consuming but not validating external data.
https://2ality.com/2020/06/validating-data-typescript.html#picking-a-library https://2ality.com/2020/06/validating-data-typescript.html#p...