@typescript-eslint/consistent-type-exports
Require export type for exports that are only types
Also called typescript-eslint/consistent-type-exports, typescript/consistent-type-exports
export { User } from "./models" doesn't say whether User is a type or a value. A tool that compiles one file at a time can't open ./models to find out whether to keep the export or drop it. export type { User } spells it out. The export is a type, and it's removed from the JavaScript output.
--fix adds the type keyword.
Configure#
Off by default. This rule needs types, so turning it on makes bun lint type check your code first.
[lint.rules]
"@typescript-eslint/consistent-type-exports" = "error" # or "warn"Every option, set to its default:
[lint.rules]
"@typescript-eslint/consistent-type-exports" = ["error", {
fixMixedExportsWithInlineTypeSpecifier = false,
}]Examples#
interface User {
name: string;
}
export { User };All exports in the declaration are only used as types. Use export type.export interface User {
name: string;
}
export type Id = string;export { User } from "./models";All exports in the declaration are only used as types. Use export type.
export * from "./models";All exports in the declaration are only used as types. Use export type.interface User {
name: string;
}
const admin: User = { name: "Ada" };
export type { User };
export { admin };Options#
| Option | Default | What it does |
|---|---|---|
fixMixedExportsWithInlineTypeSpecifier | false | How --fix repairs an export that mixes types and values. |
An export that mixes the two is reported with either setting:
interface User {
name: string;
}
const admin: User = { name: "Ada" };
export { User, admin };Type export User is not a value and should be exported using export type.With false, --fix splits it into export type { User } and export { admin }. With true, it marks the type inside the braces. Both forms are accepted with either setting.
interface User {
name: string;
}
const admin: User = { name: "Ada" };
export { type User, admin };