🤖 Warning: You must enable TypeScript'sstrictNullChecks
option in yourtsconfig.json
for Superstruct to work properly with "optional" types. Note thatstrictNullChecks
is disabled by default. If you enablestrict
,strictNullChecks
will automatically be enabled.
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.