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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 21 of 56 · Typescript

Modules – ES6 Imports/Exports & Namespaces

Duration: 20 minutes

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.

Previous: Decorators (Experimental) – Class & MethodNext: Declaration Merging & Ambient Declarations