Skip to content
← Back to rules

typescript/consistent-type-exports Nursery

💭 This rule requires type information.

它做了什么

强制对仅用作类型的导出使用 export type

为什么这是不好的?

在没有使用 export type 的情况下,将仅类型导出与值导出混合在一起,会使模块的意图更难理解,并可能导致不必要的运行时导出表面。

示例

此规则的错误代码示例:

ts
type Foo = { bar: string };
export { Foo };

export { TypeOnly, value } from "./mod";

此规则的正确代码示例:

ts
type Foo = { bar: string };
export type { Foo };

export type { TypeOnly } from "./mod";
export { value } from "./mod";

配置

此规则接受一个配置对象,包含以下属性:

fixMixedExportsWithInlineTypeSpecifier

type: boolean

默认值: false

启用一种自动修复策略,通过内联 type 指定符重写混合导出。

如何使用

要通过配置文件或 CLI 启用此规则,可以使用:

json
{
  "rules": {
    "typescript/consistent-type-exports": "error"
  }
}
bash
oxlint --type-aware --deny typescript/consistent-type-exports

参考资料