Rules

no-instanceof-error

Avoid normalizing caught values using instanceof Error.

Purpose and behavior

Avoid normalizing caught values using instanceof Error.

Reports instanceof with the right-hand identifier Error. Other constructors such as TypeError are not reported. Carry unknown caught values unchanged in a structured error field.

Options

No configurable options. Enable with "rules/no-instanceof-error": "error".

Invalid example

const isError = error instanceof Error

Valid example

new ConfigFileError({ error })

Fixes and exceptions

This rule reports diagnostics without an automatic fix. Rewrite the code deliberately rather than guessing its intended semantics.

For a genuine boundary exception, use an oxlint-disable-next-line rules/no-instanceof-error -- reason comment. Examples illustrate this rule alone and may omit imports and declarations.

Source and tests

Enabled by the Effect preset.

no-instanceof-error.ts · Tests