简体   繁体   English

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

[英]tslint: namespace and module are disallowed

I recently got a legacy .ts-file and want to update it. 我最近有一个旧的.ts文件,想要更新它。

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. 我读到有关使用标准化ES6样式的外部模块的信息,但我不知道如何执行此操作。

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 捷运

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. 来自linter的警告是关于export module MyModule ,因为MyModule不是模块而是名称空间。 The keyword that should be used is namespace : export namespace MyModule . 应该使用的关键字是namespaceexport namespace MyModule

'namespace' and 'module' are disallowed 不允许使用“命名空间”和“模块”

This warning from the linter is about export namespace MySpace . 来自linter的警告是关于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 . 顶层export意味着文件是一个模块,并且将命名空间和模块一起使用是一种不好的做法

May anyone give me a hint, how to update this structure to actual style rules? 谁能给我一个提示,如何将这种结构更新为实际的样式规则?

Do not use namespace at all. 根本不要使用namespace Here is your code in a module: 这是您在模块中的代码:

export interface MyInterface
{
}

export class MyClass
{
}

// …

See also: an introduction to modules from Mozilla . 另请参阅: Mozilla的模块简介

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TsLint:不允许函数调用 - TsLint: function invocation disallowed TypeScript索引器仍然出现tslint错误“不允许通过字符串直接访问对象” - TypeScript indexer still getting tslint error “object access via string literals is disallowed” 数组扩展代码导致错误“在 TypeScript tslint 中不允许在 class 主体之外使用“this”关键字” - Array extension code results in error “The ”this“ keyword is disallowed outside of a class body” in TypeScript tslint 错误:在尝试扩展tslint-microsoft-contrib时找不到模块'tslint / lib / lint' - Error: Cannot find module 'tslint/lib/lint' when trying to extend tslint-microsoft-contrib 如何强制我的自定义 tslint 规则使用与 tslint 正在使用的相同版本的打字稿模块 - how do I force my custom tslint rule to use the same version of the typescript module as the one tslint is using 使用module-source-path启用TSlint ordered-imports规则 - Enable TSlint ordered-imports rule with module-source-path 找不到模块'./.../x.html' - TsLint / Angular-Meteor - Cannot find module './…/x.html' - TsLint / Angular-Meteor tslint错误:找不到模块'redux / todo / actions'.ts(2307) - tslint error: Cannot find module 'redux/todo/actions'.ts(2307) 打字稿中的命名空间和模块混淆? - Namespace and module confusion in typescript? 将其他模块导出为命名空间 - Export other module as namespace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM