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:
[lint.rules]
"import/consistent-type-specifier-style" = "error" # or "warn"
Every option, set to its default:
[lint.rules]
# "prefer-inline" or "prefer-top-level"
"import/consistent-type-specifier-style" = ["error", "prefer-top-level"]
Examples
Reported:
import { type User, type Session } from "./models";
import { createUser, type User } from "./models";
Not reported:
import type { User, Session } from "./models";
import { createUser } from "./models";
import type { User } from "./models";
Options
[lint.rules]
"import/consistent-type-specifier-style" = ["error", "prefer-inline"]
| Option | What 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. |
import { createUser } from "./models";
import type { User } from "./models";
import { createUser, type User } from "./models";