A schema validator library

The problem

Build a small library that describes the shape of data as a schema and both checks unknown values at run time and produces the matching TypeScript type, in the style of popular validation libraries.

Requirements

Technologies

Step by step

  1. Define a Schema<T> interface with a parse method.
  2. Write the primitive builders and test them.
  3. Write array and object builders that combine child schemas and collect errors with paths.
  4. Write the Infer type and check it with assignments that must and must not compile.
  5. Use the library to validate a JSON file of your choice.

Expected result

A typed validation library where one schema gives both the run-time check and the static type.

How it is evaluated

Ways to improve it