Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Modules – ES6 Imports/Exports & | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 21 of 56

·Typescript

Modules – ES6 Imports/Exports & Namespaces

20 minutes

Course progress38%

ES6 Module Syntax

// utils.ts
export function sum(a: number, b: number): number {
  return a + b;
}
   = ;
export
const
PI
3.1415
// main.ts
import { sum, PI } from "./utils";
console.log(sum(2, 3), PI);

Default Export

// logger.ts
export default function log(msg: string) { console.log(msg); }

// app.ts
import log from "./logger";
log("started");

Re‑exporting

export * from "./utils"; // barrel file

Namespaces (legacy)

namespace Geometry {
  export interface Circle { radius: number; }
  export function area(c: Circle) { return Math.PI * c.radius ** 2; }
}

const c: Geometry.Circle = { radius: 5 };
console.log(Geometry.area(c));

Info

Prefer ES modules for modern projects; namespaces are useful for global augmentations.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonDecorators (Experimental) – Class & MethodContinue to lesson 22Declaration Merging & Ambient DeclarationsBack to TypeScript Mastery curriculum