errorMessages
Requires a message value when creating a built-in error.
✅ This rule is included in the ts logicalStrict presets.
This rule enforces passing a message value when creating an instance of a built-in Error object.
Error instances without messages are harder to debug because they don’t explain what went wrong.
The rule applies to all built-in error constructors:
ErrorTypeErrorRangeErrorReferenceErrorSyntaxErrorEvalErrorURIErrorAggregateError
Examples
Section titled “Examples”throw new Error();throw new TypeError();throw new Error("");throw new Error(undefined);throw new Error("Something went wrong");throw new TypeError("Expected a number");throw new RangeError(`Value must be between ${min} and ${max}`);throw new Error(getErrorMessage());Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase has legitimate reasons to throw errors without messages, such as for internal control flow that users never see, you may disable this rule. However, providing descriptive error messages is generally recommended for better debugging experience.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useErrorMessage - ESLint:
unicorn/error-message - Oxlint:
unicorn/error-message
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.