Skip to content

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:

  • Error
  • TypeError
  • RangeError
  • ReferenceError
  • SyntaxError
  • EvalError
  • URIError
  • AggregateError
throw new Error();
throw new TypeError();
throw new Error("");
throw new Error(undefined);

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.