🤖 Warning: You must enable TypeScript's
strictNullChecksoption in your
tsconfig.jsonfor Superstruct to work properly with "optional" types. Note that
strictNullChecksis disabled by default. If you enable
strictNullCheckswill automatically be enabled.
asserthelpers in Superstruct, TypeScript will infer information about your data and give you type safety. For example:
ifblock you can safely access the
Describeutility. For example:
idproperty will cause TypeScript's compilation checks to throw an error. This way your compile-time and run-time validations are never out of sync.
Inferutility. For example:
Usertype above is the same as if you'd defined it by hand:
🤖 Notice that in each of the cases above, the
Usertype and the
Userstruct have the same name! This is handy for importing them elsewhere in the codebase at the same time.