# prefer-namespace-keyword

Rule `typescript/prefer-namespace-keyword`. Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules

- Source: typescript
- Technologies: TypeScript
- Kind: correctness
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 260.7M weekly downloads of presets that enable it
- Trend: +52.6% last quarter
- Rank: #50 by reach, #757 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/prefer-namespace-keyword` | yes | safe | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/prefer-namespace-keyword) |
| Oxlint | `typescript/prefer-namespace-keyword` | yes | safe | plugin `typescript`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-namespace-keyword.html) |
| Biome | `suspicious/useNamespaceKeyword` | yes | safe | group suspicious, since 1.0.0 | [docs](https://biomejs.dev/linter/rules/use-namespace-keyword/) |

## Code examples

### Incorrect: the rule reports this

```ts
module Example {}
```

### Correct: the rule accepts this

```ts
namespace Example {}

declare module 'foo' {}
```

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/prefer-namespace-keyword": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/prefer-namespace-keyword": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "useNamespaceKeyword": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [typescript-eslint recommended](https://lintradar.dev/presets/typescript-eslint-recommended.md) | ESLint | `@typescript-eslint/eslint-plugin` | 24 | 175.9M | +29.5% |
| [Oxlint default](https://lintradar.dev/presets/oxlint-default.md) | Oxlint | `oxlint` | 111 | 50.8M | +183.6% |
| [typescript-eslint strict](https://lintradar.dev/presets/typescript-eslint-strict.md) | ESLint | `@typescript-eslint/eslint-plugin` | 32 | 175.9M | +29.5% |
| [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% |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [Nuxt](https://lintradar.dev/presets/nuxt.md) | ESLint | `@nuxt/eslint-config` | 188 | 1.5M | +72.8% |
| [Anthony Fu's config](https://lintradar.dev/presets/antfu.md) | ESLint | `@antfu/eslint-config` | 294 | 758.7K | +49.9% |
| [Google TypeScript Style](https://lintradar.dev/presets/gts.md) | ESLint | `gts` | 71 | 553.3K | +10.3% |
| [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% |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [typescript/no-this-alias](https://lintradar.dev/rules/typescript/no-this-alias.md): Disallow aliasing `this`
- [typescript/no-extra-non-null-assertion](https://lintradar.dev/rules/typescript/no-extra-non-null-assertion.md): Disallow extra non-null assertions
- [typescript/no-non-null-asserted-optional-chain](https://lintradar.dev/rules/typescript/no-non-null-asserted-optional-chain.md): Disallow non-null assertions after an optional chain expression
- [typescript/no-misused-new](https://lintradar.dev/rules/typescript/no-misused-new.md): Enforce valid definition of `new` and `constructor`
- [typescript/no-duplicate-enum-values](https://lintradar.dev/rules/typescript/no-duplicate-enum-values.md): Disallow duplicate enum member values
- [typescript/no-unsafe-declaration-merging](https://lintradar.dev/rules/typescript/no-unsafe-declaration-merging.md): Disallow unsafe declaration merging

---

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