# Modules: import & export — TypeScript

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

> Split code across files and share types and values between them.

## 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

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