typescript - tslint:不允许命名空间和模块

标签 typescript module namespaces 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
    {
    }
    ...
  }
}

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

非常感谢你们!

最好的祝福

捷运

最佳答案

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



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

'namespace' and 'module' are disallowed



来自 linter 的这个警告是关于 export namespace MySpace .顶级export表示文件是一个模块,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?



不要使用 namespace一点也不。这是您在模块中的代码:
export interface MyInterface
{
}

export class MyClass
{
}

// …

另见:an introduction to modules from Mozilla .

关于typescript - tslint:不允许命名空间和模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56059351/

相关文章:

visual-studio - Visual Studio Team Services 构建 Typescript 错误

javascript - Typescript - 没有参数类型为 'string' 的索引签名

php - 确定是否启用了 Magento 模块

node.js - 如何在没有 Typescript/TSD 定义的情况下将库导入 Node ?

typescript - 为什么要导出同名的类和命名空间?

javascript - Angular 2中的密码确认

javascript - 修改数组所有元素的值

TypeScript:如何在命名空间中使用内部接口(interface)

wpf - 当应用程序类型为类库时,未定义的CLR namespace

visual-studio - 为什么在 Silverlight 4/VS 2010 的命名空间内使用 using 指令?