Skip to content

noUselessEmptyExport

诊断类别:lint/complexity/noUselessEmptyExport

¥Diagnostic Category: lint/complexity/noUselessEmptyExport

自从:v1.0.0

¥Since: v1.0.0

来源:

¥Sources:

禁止在模块文件中不更改任何内容的空导出。

¥Disallow empty exports that don’t change anything in a module file.

export {} 有时可用于将原本是脚本的文件转换为模块。根据 TypeScript 手册模块页面

¥An empty export {} is sometimes useful to turn a file that would otherwise be a script into a module. Per the TypeScript Handbook Modules page:

在 TypeScript 中,与 ECMAScript 2015 一样,任何包含顶层导入或导出的文件都被视为模块。相反,没有任何顶层导入或导出声明的文件将被视为其内容在全局范围内可用的脚本。

¥In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. Conversely, a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope.

但是,如果文件中有任何其他顶层导入或导出,export {} 语句将不执行任何操作。

¥However, an export {} statement does nothing if there are any other top-level import or export in the file.

¥Examples

¥Invalid

import { A } from "module";
export {};
code-block.js:2:1 lint/complexity/noUselessEmptyExport  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This empty export is useless because there’s another export or import.

1 │ import { A } from “module”;
> 2 │ export {};
^^^^^^^^^^
3 │

This import makes useless the empty export.

> 1 │ import { A } from “module”;
^^^^^^
2 │ export {};
3 │

Safe fix: Remove this useless empty export.

1 1 import { A } from “module”;
2 - export·{};
3 2

export const A = 0;
export {};
code-block.js:2:1 lint/complexity/noUselessEmptyExport  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This empty export is useless because there’s another export or import.

1 │ export const A = 0;
> 2 │ export {};
^^^^^^^^^^
3 │

This export makes useless the empty export.

> 1 │ export const A = 0;
^^^^^^
2 │ export {};
3 │

Safe fix: Remove this useless empty export.

1 1 export const A = 0;
2 - export·{};
3 2

¥Valid

export {};

¥Related links