TypeScript uses ES modules for code organization.
Getting Started
What is TypeScript?
Basic Types
Types & Interfaces
Async TypeScript
Promises & Async/Await
TypeScript
Intermediate
FREE
Import & Export
Lesson 1 of 17
Intermediate
Interactive
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);