Skip to content

assert

Import from @varavel/vdl-plugin-sdk/utils/misc.

function assert(condition, message): asserts condition;

Asserts that a given condition is true. If the condition is false, an error is thrown with the provided message.

Parameters

Parameter Type Description
condition unknown The condition to evaluate.
message string The error message to throw if the condition is false.

Returns

asserts condition

Returns void if the condition is true.

Throws

Throws an error if the condition is false.

Example

// This call will succeed without any errors
assert(true, 'This should not throw');

// This call will fail and throw an error with the message 'This should throw'
assert(false, 'This should throw');