Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials TypeScript Import & Export
TypeScript Intermediate FREE

Import & Export

Lesson 1 of 17 Intermediate Interactive

TypeScript uses ES modules for code organization.

Syntax

TYPESCRIPT
// math.ts
export function add(a: number, b: number): number {
    return a + b;
}

// app.ts
import { add } from "./math";
console.log(add(1, 2));
Module Import/Export
TYPESCRIPT
// math.ts
export function add(a: number, b: number): number {
    return a + b;
}

export function multiply(a: number, b: number): number {
    return a * b;
}

export default class Calculator {
    result = 0;
    add(n: number) { this.result += n; return this; }
}

// app.ts
import Calculator, { add, multiply } from "./math";
console.log(add(2, 3));
let calc = new Calculator();
calc.add(5);