typescript/consistent-type-exports Style
作用
强制对仅作为类型使用的导出使用 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
default: false
启用一种自动修复策略,使用内联 type 说明符重写混合导出。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"options": {
"typeAware": true
},
"rules": {
"typescript/consistent-type-exports": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
options: { typeAware: true },
rules: {
"typescript/consistent-type-exports": "error",
},
});bash
oxlint --type-aware --deny typescript/consistent-type-exports版本
此规则于 v0.0.8 中添加。
