Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

TypeScript TS1484: 'X' is a type and must be imported using a type-only import

TS1484 means the compiler cannot tell if an imported name survives to runtime. Mark type imports inline, fix barrels, and keep decorated signatures intact.

~5 min readTypeScript
#typescript#ts1484#verbatimmodulesyntax#tsconfig
Bold white headline reading TS1484 TYPE ONLY with a TypeScript crate split between a cyan value card and an erased amber type card.

Introduction & Quick Summary

TypeScript refuses to compile with a message like this:

code
src/api/users.ts:3:10 - error TS1484: 'User' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

It appears the moment "verbatimModuleSyntax": true lands in tsconfig.json, or when a framework starter turns it on for you. The compiler is not saying the import is unused or misspelled. It is saying it cannot tell whether the name survives to runtime, so it refuses to guess.

Quick answer: mark the import as types-only, either as a statement or inline:

ts
import type { User } from "./types"; import { type Role, parseUser } from "./types"; // mixed module, one statement

Both are erased at emit. Use the inline form when one module exports both types and values, because parseUser stays a real import and Role disappears.

Where it shows up most often: a types.ts imported into a route handler, import { ReactNode } from "react" next to a hook, NestJS classes used only in constructor parameter types, index.ts barrels, and codemods that added import type everywhere.

Core Mechanics, Signatures & Reproducible Setup

Before TypeScript 5.0, the compiler decided per statement whether an import had to survive by checking how each binding was used, then deleted the statement if nothing remained. That speculation is import elision. It is invisible in a normal build and breaks in two places: a transpiler without type information (esbuild, SWC, Babel) cannot repeat it, and a module imported only for side effects can vanish.

verbatimModuleSyntax removes the speculation. Every import and export statement is emitted as written, minus anything you explicitly marked type. Nothing is inferred, nothing is dropped.

{ "compilerOptions": { "module": "esnext", "moduleResolution": "bundler", "verbatimModuleSyntax": true, "isolatedModules": true, "target": "es2022" } }

Reproduce it in one directory, which is worth doing before touching a large tree:

bash
npm i -D typescript@5.9 cat > types.ts <<'EOF' export interface User { id: string; email: string } export function parseUser(raw: unknown): User { return raw as User } EOF cat > main.ts <<'EOF' import { User, parseUser } from "./types"; const u: User = parseUser({}); console.log(u); EOF npx tsc --noEmit --strict --verbatimModuleSyntax --module esnext --moduleResolution bundler main.ts

The flag also fixes which files are ES modules. A file containing import or export syntax is emitted as ESM, full stop; a .cts file is CommonJS, where only export = and import x = require() are allowed. Hence the companion errors TS1283/TS1286: ESM syntax is not allowed in a CommonJS module when verbatimModuleSyntax is enabled.

Key Comparison Table

The flag replaced a family of older options. This is the mapping, with what still compiles:

SettingVersionsBehaviourStatus
importsNotUsedAsValues: "remove"4.5 – 5.4elides unused imports (default)removed in 5.5
importsNotUsedAsValues: "error"4.5 – 5.4forces import type for type-only namesremoved in 5.5
preserveValueImports: true4.5 – 5.4never elides a used-binding importremoved in 5.5
verbatimModuleSyntax: true5.0+emits statements verbatim, erases only type importscurrent
inline type modifier4.5+marks one specifier as type-onlycurrent

What each import form emits:

WrittenWith the flag onWith it offUse when
import type { T } from "m"nothingnothingmodule supplies only types
import { type T, fn } from "m"import { fn } from "m"import { fn } from "m"module mixes both
import { T, fn } from "m"unchanged, both namesimport { fn } if T is a typeboth are values

The errors that share this root cause:

MessageMeaningFix
TS1484a type name imported as a valueadd type to the specifier or statement
TS1205re-exporting a type when isolatedModules is onexport type { X } from "..."
TS1361erased name used as a valuedrop type for that specifier
TS1272type in a decorated signature with isolatedModulesimport type, and keep metadata in mind
TS1286 / TS1287ESM syntax inside a CommonJS filerename to .mts or switch to require

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Mixed modules: the inline modifier beats two statements

Two imports from one path is legal but invites a third:

ts
import type { User, Role } from "./types"; import { parseUser } from "./types"; import { type User, type Role, parseUser } from "./types"; // preferred

import { type FC, useState } from "react" is the everyday version of this rule and survives the flag unchanged.

2. Codemods: convert a tree and keep the diff readable

The consistent-type-imports rule rewrites automatically; then compile:

bash
npx eslint . --ext .ts,.tsx --fix \ --rule '{"@typescript-eslint/consistent-type-imports":["error",{"prefer":"type-imports","fixStyle":"inline-type-imports"}]}' npx tsc -p . --noEmit

inline-type-imports yields one statement per module, so one line changes per edit. separate-type-imports yields the two-statement form. The compiler accepts both; only the review cost differs.

3. Barrels need export type

ts
export { User, Order } from "./models"; // TS1205 once isolatedModules is on export { type User, type Order } from "./models"; // fixed export type { User as AppUser } from "./models"; // rename while re-exporting

export * from "./models" is safe: the compiler never has to classify names it does not enumerate. That is why some codebases enable the flag with zero changes.

4. Decorated signatures in NestJS, Angular and TypeORM

emitDecoratorMetadata writes constructor parameter types into runtime metadata, so those types must exist as values — while isolatedModules plus decorators pushes the other way. The rule that resolves it:

ts
import { Repository } from "typeorm"; // class used as a value: design:paramtypes import type { User } from "../entities/user"; // only inside a generic argument @Injectable() export class UserService { constructor(private readonly repo: Repository<User>) {} }

Mark the class itself import type and metadata records Object; the build stays green and dependency injection fails at runtime with "Nest can't resolve dependencies".

5. Test runners and transpilers that ignore types

Vitest, babel-jest, @swc/jest and tsx strip types without checking them. With the flag on, the source already declares what is erasable, so their output matches tsc:

ts
import { describe, it, expect, vi } from "vitest"; import type { Mock } from "vitest"; import { UserService } from "./user.service"; import type { User } from "./user";

A test failing with SyntaxError: The requested module './types' does not provide an export named 'User' still has a value import for a type-only module. Add type; the logic does not change.

6. Const enums and namespaces

import type * as ts from "typescript" is legal when you touch only its types. const enum is the trap: with isolatedModules another file cannot inline it, and TS2748 appears. Replace it with a literal union, which needs no runtime import at all:

ts
export const ROLES = ["admin", "editor", "viewer"] as const; export type Role = (typeof ROLES)[number];

Common Compilation/Runtime Mistakes & Version Gotchas

Enabling the flag under "module": "commonjs". Every file with ESM syntax then fails with TS1286. Turn it on with "module": "esnext" or "node16" and migrate the few files that genuinely need require.

Marking a class import type and later calling new, instanceof, or using it as a decorator. TS1361 is the friendly version of that mistake. The unfriendly version is a DI container resolving it by string at runtime.

Expecting the flag to make side-effect imports safer. It adds nothing; it only stops deleting. import "./polyfills" was always preserved. What changes is that import { unused } from "pkg" is no longer silently dropped, which can expose packages that had been tree-shaken by accident.

Version boundaries. The inline modifier arrived in 4.5, verbatimModuleSyntax in 5.0, and importsNotUsedAsValues/preserveValueImports were removed in 5.5 — a tsconfig.json copied from a 2022 article now fails with Unknown compiler option. TypeScript 5.5 and later also mark type-only imports in the .d.ts output, so declaration consumers see the same classification.

CommonJS packages that use export =. Under ESM emit these need import pkg from "pkg" with esModuleInterop, or import pkg = require("pkg") in a .cts file. A default import that worked with allowSyntheticDefaultImports alone can start failing once the module format is fixed.

Verify the emit, do not reason about it. Compile with --outDir dist and open the output: type-only lines are gone, everything else is byte-for-byte the source. Compare two builds with the text diff tool rather than the input, since only the emitted file reaches the runtime. Import linters that parse source text need patterns such as ^import\s+(?!type\b); test them on the regular expression tester before a repository-wide codemod.

Reference material: verbatimModuleSyntax and the TypeScript 5.0 release notes.

Official references

primary documentation

The TypeScript documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit TypeScript work — they run entirely in this browser tab, so nothing you paste leaves your device.

All TypeScript guides

More in TypeScript

All TypeScript guides

The guides filed next to this one in TypeScript, in library order.