Rust-style assertion with a typed error parameter.
The type of the error
The condition to assert
The error object to return if the condition is false
Whether to throw the error instead of returning a Result (defaults to true)
A Result that is ok(true) if condition is true, or err(error) if false
If shouldThrow is true and condition is false
const check = assertOr( user.isAdmin, new PermissionError("Admin access required"))if (!check.ok) return check Copy
const check = assertOr( user.isAdmin, new PermissionError("Admin access required"))if (!check.ok) return check
Rust-style assertion with a typed error parameter.