We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Importing Types

With certain TypeScript configurations you can import types directly from a module:

import { User, Post } from "./models";

But it's much safer and more efficient to use the import type syntax:

import type { User, Post } from "./models";

This way TypeScript knows that you're only importing types, and it can drop the imports so they don't generate extra JavaScript code when your project is compiled. This means a smaller final bundle size. This syntax also works:

import { type User, type Post } from "./models";

But personally I prefer the first one. It's more concise and keeps all my type imports in one place.