# Modules: import & export — TypeScript Fundamentals

Source: https://www.skillbyai.com/en/typescript/ts-modules

> Split TypeScript code into modules with named and default exports, and use import type to keep output lean.

## Named exports

A file can export as many named values, functions, types or interfaces as it needs.

```typescript
// math.ts
export function add(a: number, b: number): number {
  return a + b;
}
export interface Point {
  x: number;
  y: number;
}
```

## Default export & import

A file has at most one `export default` — imported without curly braces, and can be renamed freely.

```typescript
// logger.ts
export default function log(msg: string) {
  console.log(`[LOG] ${msg}`);
}

// app.ts
import myLogger from "./logger";
import { add, Point } from "./math";

myLogger("started");
```

## Type-only imports

`import type { Point } from "./math"` imports only the type, which is erased entirely at compile time — nothing extra ships in the output JS.

**Quiz:** How many `export default` statements can one file have?

- [x] At most one
- [ ] Unlimited
- [ ] Exactly one per interface
- [ ] Two, one for types and one for values

*Answer:* At most one. A module can have many named exports but only a single default export.
