close

no-namespace

Configuration

PresetConfigured Value
✅ ts.configs.recommended"error"
rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-namespace': 'error',
    },
  },
]);

Rule Details

Disallows the use of TypeScript namespace declarations. TypeScript historically allowed organizing code with custom namespace blocks, but ES2015 modules (using import/export) are the modern standard for code organization. Namespaces are generally considered outdated and should be replaced with modules. By default, this rule allows namespaces in .d.ts definition files, since they are commonly used there.

Examples of incorrect code for this rule:

namespace MyNamespace {
  export const value = 1;
}

namespace Nested {
  export namespace Inner {
    export type Foo = string;
  }
}

Examples of correct code for this rule:

// Use ES modules instead
export const value = 1;

// Declare namespaces are allowed with allowDeclarations option
declare namespace ExternalLib {
  function doWork(): void;
}

// Namespaces in .d.ts files are allowed by default
// (in file.d.ts)
declare namespace MyLib {
  interface Options {}
}

Original Documentation