Javascript has a few good libraries for data validation. If you’re using TypeScript, you probably will want a library that can not only validate your data, but also can generate static types automatically. There are a few libraries that aim at solving that problem, but the most popular right now are class-validator and io-ts.

Class-Validator, as the name implies, requires you to create a class for each interface you want to validate and use annotations as the property validator. It makes the code very nice and clean, but if you ever want to create your own validators things become less trivial.

IO-TS uses a different approach and lets you validate any type you choose without the limitation for classes or objects. The generated TypeScript interfaces are pretty robust, and the code is strongly aligned with TypeScript methodology for defined types. Creating new types is less user-friendly — it appears that many basic features like string length range are missing from the list of current types available.

There are many more solutions and libraries. I took a deep look into many of them, but I was not able to find a simple and elegant solution that satisfies my needs.