🤖 Warning: If you are not using TypeScript'sstrictNullChecks
option, Superstruct will be unable to infer your "optional" types correctly and will mark all types as optional.
is
or assert
helpers in Superstruct, TypeScript will infer information about your data and give you type safety. For example:if
block you can safely access the User
properties id
, name
and email
because TypeScript knows that the data already passed validation.Describe
utility. For example:id
property will cause TypeScript's compilation checks to throw an error. This way your compile-time and run-time validations are never out of sync.Infer
utility. For example:User
type above is the same as if you'd defined it by hand:🤖 Notice that in each of the cases above, theUser
type and theUser
struct have the same name! This is handy for importing them elsewhere in the codebase at the same time.