Conditionally asserts a condition only when a value is defined. Does nothing if the value is undefined or null.
The value to check for definedness.
The condition to assert if value is defined.
Optional
Optional error message to throw if the assertion fails.
Error if value is defined and condition is falsy.
assertIfDefined(user, user?.age >= 18, 'User must be an adult') Copy
assertIfDefined(user, user?.age >= 18, 'User must be an adult')
Conditionally asserts a condition only when a value is defined. Does nothing if the value is undefined or null.