import/consistent-type-specifier-style

Enforce one way to mark type-only imports: import type { A } or import { type A }

fixable

Also called import-x/consistent-type-specifier-style

TypeScript has two ways to mark an import as type-only: import type { User } for the whole statement, or import { type User } for one name. This rule keeps a project on one of them.

The two compile differently with verbatimModuleSyntax. import type { User } from "./user" is removed, while import { type User } from "./user" is left as import {} from "./user" and still loads the module.

By default the rule asks for import type. Imports without braces, such as import type User from "./user", are never reported.

--fix rewrites the import in the style you chose.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"import/consistent-type-specifier-style" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
# "prefer-inline" or "prefer-top-level"
"import/consistent-type-specifier-style" = ["error", "prefer-top-level"]

Examples#

example.ts1 problem
import { type User, type Session } from "./models";
example.ts1 problem
import { createUser, type User } from "./models";
example.tsNo problems
import type { User, Session } from "./models";
example.tsNo problems
import { createUser } from "./models";
import type { User } from "./models";

Options#

bunfig.toml
[lint.rules]
"import/consistent-type-specifier-style" = ["error", "prefer-inline"]
OptionWhat it does
"prefer-top-level" (default)Report import { type User }. Types go in their own import type statement.
"prefer-inline"Report import type { User }. Each type is marked by name, so one import statement per module is enough.
example.tswith "prefer-inline"1 problem
import { createUser } from "./models";
import type { User } from "./models";
example.tswith "prefer-inline"No problems
import { createUser, type User } from "./models";