> For the complete documentation index, see [llms.txt](https://radlohead.gitbook.io/typescript-deep-dive/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://radlohead.gitbook.io/typescript-deep-dive/main-1/barrel.md).

# Import 여러개 하기

배럴은 여러 모듈의 익스포트를 편리하게 하나의 모듈로 모으는 방법입니다. 배럴은 다른 모듈의 익스포트를 모아서 다시 익스포트하는 모듈 파일입니다.

라이브러리에 다음과 같은 클래스 구조가 있다고 생각해보세요:

```typescript
// demo/foo.ts
export class Foo {}

// demo/bar.ts
export class Bar {}

// demo/baz.ts
export class Baz {}
```

배럴이 없으면 다음과 같이 세 번 임포트해야 합니다:

```typescript
import { Foo } from '../demo/foo';
import { Bar } from '../demo/bar';
import { Baz } from '../demo/baz';
```

대신 `demo/index.ts` 라는 배럴을 다음과 같은 내용으로 만들 수 있습니다:

```typescript
// demo/index.ts
export * from './foo'; // 이 모듈의 모든 익스포트를 다시 익스포트
export * from './bar'; // 이 모듈의 모든 익스포트를 다시 익스포트
export * from './baz'; // 이 모듈의 모든 익스포트를 다시 익스포트
```

이제 사용자는 필요한 것들을 배럴로부터 임포트할 수 있습니다:

```typescript
import { Foo, Bar, Baz } from '../demo'; // demo/index.ts 를 가리킴
```

## 이름 붙인 익스포트

익스포트를 `*` 로 하는 대신 이름을 붙여서 익스포트할 수 있습니다. 예를 들어 `baz.ts`에 다음과 같은 함수가 있다면:

```typescript
// demo/foo.ts
export class Foo {}

// demo/bar.ts
export class Bar {}

// demo/baz.ts
export function getBaz() {}
export function setBaz() {}
```

`getBaz` / `setBaz` 라고 익스포트하지 않고 변수에 담아서 익스포트하려면 아래 나온 것처럼 먼저 이름을 붙여서 임포트한 다음 익스포트하면 됩니다:

```typescript
// demo/index.ts
export * from './foo'; // 이 모듈의 모든 익스포트를 다시 익스포트
export * from './bar'; // 이 모듈의 모든 익스포트를 다시 익스포트

import * as baz from './baz'; // 이름으로 임포트
export { baz }; // 그 이름을 익스포트
```

다음과 같이 사용하게 됩니다:

```typescript
import { Foo, Bar, baz } from '../demo'; // demo/index.ts 를 가리킴

// usage
baz.getBaz();
baz.setBaz();
// etc. ...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://radlohead.gitbook.io/typescript-deep-dive/main-1/barrel.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
