# no-magic-numbers

Rule `typescript/no-magic-numbers`. Disallow magic numbers

- Source: typescript
- Technologies: TypeScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 171.7K weekly downloads of presets that enable it
- Trend: +39.3% last quarter
- Rank: #1639 by reach, #1029 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/no-magic-numbers` | no | no | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/no-magic-numbers) |
| Biome | `style/noMagicNumbers` | no | no | group style, since 2.1.0 | [docs](https://biomejs.dev/linter/rules/no-magic-numbers/) |

## Code examples

### Incorrect: the rule reports this

```ts
enum foo {
  SECOND = 1000,
}
```

```ts
type SmallPrimes = 2 | 3 | 5 | 7 | 11;
```

```ts
class Foo {
  readonly A = 1;
  readonly B = 2;
  public static readonly C = 1;
  static readonly D = 1;
}
```

### Correct: the rule accepts this

```ts
enum foo {
  SECOND = 1000,
}
```

```ts
type SmallPrimes = 2 | 3 | 5 | 7 | 11;
```

```ts
class Foo {
  readonly A = 1;
  readonly B = 2;
  public static readonly C = 1;
  static readonly D = 1;
}
```

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/no-magic-numbers": "error",
    },
  },
];
```

### Biome: `biome.json`

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

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [eslint/no-magic-numbers](https://lintradar.dev/rules/eslint/no-magic-numbers.md): Disallow magic numbers
- [typescript/max-params](https://lintradar.dev/rules/typescript/max-params.md): Enforce a maximum number of parameters in function definitions
- [typescript/prefer-destructuring](https://lintradar.dev/rules/typescript/prefer-destructuring.md): Require destructuring from arrays and/or objects
- [typescript/class-methods-use-this](https://lintradar.dev/rules/typescript/class-methods-use-this.md): Enforce that class methods utilize `this`
- [typescript/explicit-function-return-type](https://lintradar.dev/rules/typescript/explicit-function-return-type.md): Require explicit return types on functions and class methods
- [typescript/init-declarations](https://lintradar.dev/rules/typescript/init-declarations.md): Require or disallow initialization in variable declarations

---

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