@typescript-eslint/no-import-type-side-effects
Require import type when every name in an import is marked type
fixable
Also called typescript-eslint/no-import-type-side-effects, typescript/no-import-type-side-effects
With verbatimModuleSyntax in tsconfig.json, TypeScript removes the names marked type from an import and keeps the rest of the statement. import { type User } from "./models" becomes import {} from "./models", so the module is still loaded and run. import type { User } from "./models" is removed completely.
--fix moves type in front of the braces.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"@typescript-eslint/no-import-type-side-effects" = "error" # or "warn"Examples#
example.ts1 problem
import { type User, type Role } from "./models";TypeScript will only remove the inline type specifiers which will leave behind a side effect import at runtime. Convert this to a top-level type qualifier to properly remove the entire import.
export function describe(user: User, role: Role) {}example.tsNo problems
import type { User, Role } from "./models";
export function describe(user: User, role: Role) {}An import that also brings in a value must stay at run time, so it's fine:
example.tsNo problems
import { type User, loadUser } from "./models";
export const user: User = loadUser();When not to use it#
Without verbatimModuleSyntax, TypeScript drops an import that's only used for types, so both forms compile to the same code.