useExportType
诊断类别:lint/style/useExportType
¥Diagnostic Category: lint/style/useExportType
自从:v1.5.0
¥Since: v1.5.0
来源:
¥Sources:
-
灵感来自:
@typescript-eslint/consistent-type-exports
¥Inspired from:
@typescript-eslint/consistent-type-exports
提倡使用 export type
作为类型。
¥Promotes the use of export type
for types.
TypeScript 允许在 export
上指定 type
标记,以指示 export
在运行时不存在。这允许转译器安全地删除类型的导出而无需查找其定义。
¥TypeScript allows specifying a type
marker on an export
to indicate that the export
doesn’t exist at runtime.
This allows transpilers to safely drop exports of types without looking for their definition.
该规则确保使用仅类型的 export
导出类型。它还将内联类型导出分组到分组的 export type
中。
¥The rule ensures that types are exported using a type-only export
.
It also groups inline type exports into a grouped export type
.
¥Examples
¥Invalid
code-block.ts:2:8 lint/style/useExportType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ All exports are only types and should thus use export type.
1 │ interface I {}
> 2 │ export { I };
│ ^^^^^^
3 │
ℹ Using export type allows transpilers to safely drop exports of types without looking for their definition.
ℹ Safe fix: Use a grouped export type.
2 │ export·type·{·I·};
│ +++++
code-block.ts:2:8 lint/style/useExportType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ All exports are only types and should thus use export type.
1 │ type T = number;
> 2 │ export { T };
│ ^^^^^^
3 │
ℹ Using export type allows transpilers to safely drop exports of types without looking for their definition.
ℹ Safe fix: Use a grouped export type.
2 │ export·type·{·T·};
│ +++++
code-block.ts:2:8 lint/style/useExportType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ All exports are only types and should thus use export type.
1 │ import type { T } from “./mod.js”;
> 2 │ export { T };
│ ^^^^^^
3 │
ℹ Using export type allows transpilers to safely drop exports of types without looking for their definition.
ℹ Safe fix: Use a grouped export type.
2 │ export·type·{·T·};
│ +++++
code-block.ts:1:8 lint/style/useExportType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ All exports are only types and should thus use export type.
> 1 │ export { type X, type Y };
│ ^^^^^^^^^^^^^^^^^^^
2 │
ℹ Using export type allows transpilers to safely drop exports of types without looking for their definition.
ℹ Safe fix: Use a grouped export type.
1 │ - export·{·type·X,·type·Y·};
1 │ + export·type·{·X,·Y·};
2 2 │
¥Valid
此规则仅检查文件中定义的标识符。它不会对在重新导出子句中作为值导出的类型发出警告,例如:
¥This rules checks only the identifiers that are defined in a file. It doesn’t warn against a type exported as a value in a re-export clause such as:
¥Related links