Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tslint: namespace and module are disallowed

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

like image 842
mrt Avatar asked May 09 '19 12:05

mrt


People also ask

What is the difference between namespace and module in TypeScript?

A module is a way which is used to organize the code in separate files and can execute in their local scope, not in the global scope. A namespace is a way which is used for logical grouping of functionalities with local scoping.

How do I refer a namespace in a file student ts?

To use it, it must be included using triple slash reference syntax e.g. ///<reference path="path to namespace file" /> . Must import it first in order to use it elsewhere. Compile using the --outFile command. Compile using the --module command.

What is namespace in TypeScript?

The namespace is a way which is used for logical grouping of functionalities. It encapsulates the features and objects that share common relationships. It allows us to organize our code in a much cleaner way. A namespace is also known as internal modules.

What is namespace in node JS?

Namespaces are a TypeScript-specific way to organize code. Namespaces are simply named JavaScript objects in the global namespace. This makes namespaces a very simple construct to use. Unlike modules, they can span multiple files, and can be concatenated using outFile .


1 Answers

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.

like image 156
Paleo Avatar answered Sep 27 '22 23:09

Paleo