Type-only imports (import type { Foo } from './foo') chỉ import thông tin kiểu dữ liệu và bị xóa hoàn toàn khỏi code JavaScript sau khi compile, không tạo ra bất kỳ runtime import nào.
- Điều này đặc biệt quan trọng khi bật isolatedModules (bắt buộc với Vite, esbuild) vì các bundler này compile từng file riêng lẻ và không thể biết một import là type hay value.
- Tương tự, export type { Foo } dùng để re-export chỉ type information, giúp ngăn circular dependency issues vì không tạo side effects ở runtime.
- Từ TypeScript 5.0+, ta có thể mix type và value imports trong cùng một statement: import { type Foo, bar } from './module', trong đó chỉ bar được giữ lại sau compile.