@typescript-eslint/consistent-type-exports

Require export type for exports that are only types

fixableneeds 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.

bunfig.toml
[lint.rules]
"@typescript-eslint/consistent-type-exports" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"@typescript-eslint/consistent-type-exports" = ["error", {
  fixMixedExportsWithInlineTypeSpecifier = false,
}]

Examples#

example.ts1 problem
interface User {
  name: string;
}

export { User };
models.ts
export interface User {
  name: string;
}
export type Id = string;
example.ts2 problems
export { User } from "./models";
export * from "./models";
example.tsNo problems
interface User {
  name: string;
}
const admin: User = { name: "Ada" };

export type { User };
export { admin };

Options#

OptionDefaultWhat it does
fixMixedExportsWithInlineTypeSpecifierfalseHow --fix repairs an export that mixes types and values.

An export that mixes the two is reported with either setting:

example.ts1 problem
interface User {
  name: string;
}
const admin: User = { name: "Ada" };

export { User, admin };

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.

example.tsNo problems
interface User {
  name: string;
}
const admin: User = { name: "Ada" };

export { type User, admin };