@typescript-eslint/prefer-namespace-keyword
Require namespace instead of module to declare a namespace
warn by defaultfixable
Also called typescript-eslint/prefer-namespace-keyword, typescript/prefer-namespace-keyword
module Shapes {} declares a namespace. It has nothing to do with modules in the usual sense, which are files with import and export. namespace Shapes {} means the same thing and can't be confused with them.
declare module "name" with the name in quotes describes a package or a file. There's no other way to write it, so it's left alone.
--fix replaces the keyword.
This rule is on by default in TypeScript files.
Configure#
On by default as a warning. To turn it off:
bunfig.toml
[lint.rules]
"@typescript-eslint/prefer-namespace-keyword" = "off" # or "error"Examples#
example.ts2 problems
module Shapes {Use namespace instead of module to declare custom TypeScript modules.
export const sides = 4;
}
declare module Vendor {Use namespace instead of module to declare custom TypeScript modules.
function init(): void;
}example.tsNo problems
namespace Shapes {
export const sides = 4;
}
declare namespace Vendor {
function init(): void;
}
declare module "vendor-package" {
export function init(): void;
}