Custom Types
Pretty much like with JSDoc @typedef one can declare a custom type and use it as a contract.
Validating against a Union Type
Here we define a union type for values that can contain either numbers or strings that represent numbers.
Validating against a Complex Type
This example defines a type #Hero
that represents an object/namespace required to have properties hasSuperhumanStrength
and hasWaterbreathing
both of boolean type.
Custom type in the example above is prefixed with sharp (#) to avoid interfering with global objects. It's not required though.
When any of properties violates the specified contract an exception thrown
If value misses a property of the complex type an exception thrown
Custom Types and modifiers
Custom type is treated the same way as any other type in JSDoc
Last updated
Was this helpful?