TypeScript
Superstruct is designed with TypeScript in mind, so that you don't need to duplicate type definitions.
Utilities
Describe
Describe
The Describe
utility returns a type representing a struct for a given valid value type. This allows you to ensure you're writing your struct definitions properly, for example:
🤖 There are limitations to what
Describe
can do, specifically it will always assume object types are as strict as possible. So describing thetype()
struct is not possible, and simple unions of strings will be required to useenums()
.
Infer
Infer
The Infer
utility type extracts the type of a valid value from a struct definition. This allows you to avoid having to duplicate effort when writing typings, for example:
🤖 If you are not using TypeScript's
strictNullChecks
option, Superstruct will be unable to infer your "optional" types correctly and will mark all types as optional.
Last updated