ES2015 module syntax is preferred over custom TypeScript modules and namespaces.eslint@typescript-eslint/no-namespace

问题

在使用vue3+vite+ts开发时,使用namespaceeslint提示如下错误:

解决方法

简单粗暴的解决方法,在.eslintrc中关闭该规则:

为什么

官方文档说明如下:

no-namespace

Disallow the use of custom TypeScript modules and namespaces.
Custom TypeScript modules (module foo {}) and namespaces (namespace foo {}) are considered outdated ways to organize TypeScript code. ES2015 module syntax is now preferred (import/export).
This rule still allows the use of TypeScript module declarations to describe external APIs (declare module 'foo' {}).

大体意思是:

no-namespace

禁止使用自定义Typescript模块和命名空间。

自定义Typescript模块(module foo {})和命名空间(namespace foo {})被认为是组织Typescript代码的过时方法ES2015模块语法现在是首选( import/export

此规则仍然允许使用Typescript声明来描述外部API(declare module 'foo' {})。

因此,还是不要关闭该规则,在框架中使用import/export吧。

官方文档

https://typescript-eslint.io/rules/no-namespace/

https://typescript-eslint.io/rules/

https://palantir.github.io/tslint/rules/no-namespace/

https://eslint.org/docs/rules/

扫码领红包

公众号

头条号