Throws an error in expression contexts.
Enables error throwing in functional style code where expressions are required, such as ternary operators, arrow functions, or array methods.
The expected return type for type compatibility (never actually returns)
The error message string or Error instance to throw
Never returns (always throws)
The provided error or a new Error with the provided message
// Use in ternary operatorconst value = isValid(input) ? input : error("Invalid input");// Use in arrow functionconst getRequired = (key: string) => map.get(key) ?? error(`Missing key: ${key}`);// Use in array methodconst items = data.map(item => item.value ?? error("Missing value")); Copy
// Use in ternary operatorconst value = isValid(input) ? input : error("Invalid input");// Use in arrow functionconst getRequired = (key: string) => map.get(key) ?? error(`Missing key: ${key}`);// Use in array methodconst items = data.map(item => item.value ?? error("Missing value"));
Throws an error in expression contexts.
Enables error throwing in functional style code where expressions are required, such as ternary operators, arrow functions, or array methods.