tslint: namespace and module are disallowed

mrt picture mrt · May 9, 2019 · Viewed 8.8k times · Source

I recently got a legacy .ts-file and want to update it.

Two of the warnings say:

'namespace' and 'module' are disallowed

and

The internal 'module' syntax is deprecated, use the 'namespace' keyword instead.

I read about using standardized ES6-style external modules, but I cannot figure out, how to do this.

My code looks like the following:

export namespace MySpace
{
  export module MyModule
  {
    export interface MyInterface
    {
    }

    export class MyClass
    {
    }
    ...
  }
}

May anyone give me a hint, how to update this structure to actual style rules?

thank you all a lot in advance!

best regards

mrt

Answer

Paleo picture Paleo · May 9, 2019

The internal 'module' syntax is deprecated, use the 'namespace' keyword instead.

This warning from the linter is about export module MyModule, because MyModule is not a module but a namespace. The keyword that should be used is namespace: export namespace MyModule.

'namespace' and 'module' are disallowed

This warning from the linter is about export namespace MySpace. A top-level export implies the file is a module, and it is a bad practice to use namespaces and modules together.

May anyone give me a hint, how to update this structure to actual style rules?

Do not use namespace at all. Here is your code in a module:

export interface MyInterface
{
}

export class MyClass
{
}

// …

See also: an introduction to modules from Mozilla.