# import type

> The `import type` syntax in TypeScript imports only type declarations that are removed from the compiled code.

## When should I use import type in TypeScript?

The syntax that imports declarations only for use in type annotations. Such imports are always fully erased during compilation, which prevents unwanted side effects and is required with `verbatimModuleSyntax`.

- Topic: Modules
- Type: syntax, keyword

## Example

Wrong:

```ts
import { User } from './types';
export function greet(u: User) {
  return u.name;
}
```

Right:

```ts
import type { User } from './types';
export function greet(u: User) {
  return u.name;
}
```

`import type` is always removed from the output, so the module is not loaded at runtime just for a type.

## Common mistakes

- Importing a class with `import type` and then calling `new` on it.

## Key points

- Imports used only as types are written with `import type` or inline `type` specifiers.
- Values like classes and enums that are used at runtime are imported without `type`.
- Type-only imports are used in files run by type stripping, where untagged type imports fail at runtime.

## Interview questions

### import type vs import { type X }: what is the difference?

`import type { X }` removes the whole statement. `import { type X, y }` removes only `X` and keeps the value import `y`.

### Can I use a class imported with import type?

Only as a type. You cannot call `new` on it or use it with `instanceof`, because the import is erased.

## Related cards

- [verbatimModuleSyntax](https://wonderium.dev/ts/verbatim-module-syntax.md)
- [Type Stripping](https://wonderium.dev/ts/type-stripping.md)
- [import / export](https://wonderium.dev/js/import-export.md)
- [erasableSyntaxOnly](https://wonderium.dev/ts/erasable-syntax-only.md)
- [Erased Types](https://wonderium.dev/ts/erased-types.md)

---

- Level: [TypeScript](https://wonderium.dev/ts.md)
- HTML version: https://wonderium.dev/ts/type-only-imports
- Last updated: 2026-11-25
