Skip to content

Latest commit

 

History

History
42 lines (26 loc) · 1.11 KB

types.basetypeimpl.assert.md

File metadata and controls

42 lines (26 loc) · 1.11 KB

Home > @skunkteam/types > BaseTypeImpl > assert

BaseTypeImpl.assert() method

Verifies that a value conforms to this Type.

Signature:

assert(input: unknown): asserts input is ResultType;

Parameters

Parameter Type Description
input unknown the value to assert

Returns:

asserts input is ResultType

Remarks

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);