ES Module Syntax: import and export
Use named and default exports in TypeScript files.
ES Module Syntax: import and export is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome
Named Exports
// math.ts
export function add(a: number, b: number): number { return a + b; }
export const PI = 3.14159;
export interface Config { host: string; }Named Imports
// app.ts
import { add, PI } from './math';
console.log(add(1, 2)); // 3
console.log(PI); // 3.14159Default Exports
// greeter.ts
export default function greet(name: string): string {
return 'Hello, ' + name;
}
// app.ts
import greet from './greeter';
console.log(greet('Alice'));Import Aliases
import { log as consoleLog } from './logger';
import { User as UserModel } from './models';Namespace Imports
import * as math from './math';
console.log(math.add(1, 2));
console.log(math.PI);Re-Exporting
// index.ts
export { add, PI } from './math';
export { greet } from './greeter';
export * from './utils';Type-Only Exports
// types.ts
export type { User, Product };
export type UserId = string;Type-Only Imports
import type { User } from './models';
// Only the type is imported — no JavaScript
function greet(user: User): string { return user.name; }Module Resolution
Importing JSON
// tsconfig.json: "resolveJsonModule": true
import config from './config.json';
console.log(config.host); // typed based on JSON structureQuick Check
Recap
Frequently asked questions
Is the “ES Module Syntax: import and export” lesson free?
Yes — the full text of “ES Module Syntax: import and export” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “ES Module Syntax: import and export”?
Use named and default exports in TypeScript files. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “ES Module Syntax: import and export” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- ES Module Syntax: import and export
- Re-exports and Barrel Files
- Type-Only Imports and Exports
- Namespaces vs Modules: Modern Usage