Importing Types

What

Importing types allows you to share type definitions across different files and modules in your project.

How

Use the import type syntax to explicitly import only the type information:

// Preferred
import type { User, APIResponse } from "./types";

// Inline alternative
import { type User, type APIResponse } from "./types";

Why

Using import type ensures that the imported items are completely removed during the compilation to JavaScript. This prevents “ghost” imports that can increase your bundle size or cause runtime errors due to circular dependencies that only exist in the type layer.

Summary

Always use import type when bringing in definitions that are only used for type-checking to keep your production bundles lean and efficient.