Skip to content
Justice Tech School

ES Modules and Imports

Use export and import. Type only imports with import type are erased. Barrel files re-export modules. Set module and moduleResolution in tsconfig to match your runtime.

Example
// math.ts
// export const add = (a: number, b: number) => a + b;
// export default function main() {}
// app.ts
// import main, { add } from "./math";
// import type { User } from "./types";
console.log("Modules keep code organised");

Result

Modules keep code organised

Exercise

Import only a type.

import  { User } from "./t";

Quiz Test

What does import type do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.