# only-throw-error

Rule `typescript/only-throw-error`. Disallow throwing non-`Error` values as exceptions

- Source: typescript
- Technologies: TypeScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 46.6M weekly downloads of presets that enable it
- Trend: +31.9% last quarter
- Rank: #271 by reach, #1097 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/only-throw-error` | no | no | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/only-throw-error) |
| Oxlint | `typescript/only-throw-error` | no | no | plugin `typescript`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/only-throw-error.html) |
| Biome | `style/useThrowOnlyError` | no | no | group style, since 1.8.0 | [docs](https://biomejs.dev/linter/rules/use-throw-only-error/) |

## Code examples

### Incorrect: the rule reports this

```ts
throw 'error';

throw 0;

throw undefined;

function getErrorString(): string {
  return '';
}
throw getErrorString();

const foo = {
  bar: 'error string',
};
throw foo.bar;

class SomeClass {
  // ...
}
throw new SomeClass();
```

### Correct: the rule accepts this

```ts
throw new Error();

throw new Error('error');

const e = new Error('error');
throw e;

function getError() {
  return new Error();
}
throw getError();

const foo = {
  bar: new Error(),
};
throw foo.bar;

class CustomError extends Error {
  // ...
}
throw new CustomError();
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/only-throw-error": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/only-throw-error": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useThrowOnlyError": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [typescript-eslint strict type-checked](https://lintradar.dev/presets/typescript-eslint-strict-type-checked.md) | ESLint | `@typescript-eslint/eslint-plugin` | 75 | 175.9M | +29.5% |
| [typescript-eslint recommended type-checked](https://lintradar.dev/presets/typescript-eslint-recommended-type-checked.md) | ESLint | `@typescript-eslint/eslint-plugin` | 47 | 175.9M | +29.5% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [typescript/no-unsafe-return](https://lintradar.dev/rules/typescript/no-unsafe-return.md): Disallow returning a value with type `any` from a function
- [typescript/prefer-promise-reject-errors](https://lintradar.dev/rules/typescript/prefer-promise-reject-errors.md): Require using Error objects as Promise rejection reasons
- [typescript/no-unnecessary-template-expression](https://lintradar.dev/rules/typescript/no-unnecessary-template-expression.md): Disallow unnecessary template expressions
- [typescript/prefer-reduce-type-parameter](https://lintradar.dev/rules/typescript/prefer-reduce-type-parameter.md): Enforce using type parameter when calling `Array#reduce` instead of using a type assertion
- [typescript/no-mixed-enums](https://lintradar.dev/rules/typescript/no-mixed-enums.md): Disallow enums from having both number and string members
- [typescript/restrict-plus-operands](https://lintradar.dev/rules/typescript/restrict-plus-operands.md): Require both operands of addition to be the same type and be `bigint`, `number`, or `string`

---

Web page: https://lintradar.dev/rules/typescript/only-throw-error. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
