tslint:不允许使用命名空间和模块

mrt*_*mrt 12 namespaces module typescript tslint

我最近得到了一个旧的 .ts 文件并想更新它。

两个警告说:

'namespace' and 'module' are disallowed

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

我阅读了有关使用标准化 ES6 样式外部模块的信息,但我不知道如何执行此操作。

我的代码如下所示:

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

    export class MyClass
    {
    }
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

谁能给我一个提示,如何将此结构更新为实际的样式规则?

非常感谢大家!

此致

地铁

Pal*_*leo 9

不推荐使用内部“模块”语法,请改用“命名空间”关键字。

这个来自 linter 的警告是 about export module MyModule,因为MyModule不是模块而是命名空间。应该使用的关键字是namespace: export namespace MyModule

'namespace' 和 'module' 是不允许的

这个来自 linter 的警告是关于export namespace MySpace. 顶层export意味着文件是一个模块,将命名空间和模块一起使用是一种不好的做法

谁能给我一个提示,如何将此结构更新为实际的样式规则?

根本不要使用namespace。这是您在模块中的代码:

export interface MyInterface
{
}

export class MyClass
{
}

// …
Run Code Online (Sandbox Code Playgroud)

另请参阅:Mozilla 模块介绍

  • 需要命名空间才能将“静态”成员添加到接口。是否有其他语法可以使用,或者我只需要禁用此 tslint 规则? (2认同)