Home > @skunkteam/types > BaseTypeImpl > assert
Verifies that a value conforms to this Type.
Signature:
assert(input: unknown): asserts input is ResultType;
Parameter | Type | Description |
---|---|---|
input | unknown | the value to assert |
Returns:
asserts input is ResultType
When given a value that does not conform to the Type, throws an exception.
Note that this method can only be used if the type object is explicitly annotated with the type, see: https://github.com/microsoft/TypeScript/issues/34596\#issuecomment-548084070
Example:
const MyImplicitType = object('MyImplicitType', { a: string });
const MyExplicitType: Type<{ a: string }> = object('MyExplicitType', { a: string });
// Does not work :
MyImplicitType.assert(value);
// Works :-D
MyExplicitType.assert(value);