> 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/type-system/intro/d.ts.md).

# 파일 선언

다른 곳에 존재하는(e.g. 자바스크립트/커피스크립트/브라우저/Node 등등) 자바스크립트코드를 설명하기 위해 Typescript 에서는 `declare` 라는 키워드를 쓸 수 있습니다. 간단한 예제를 살펴보면:

```typescript
foo = 123; // 에러: `foo` is not defined
```

vs.

```typescript
declare var foo: any;
foo = 123; // 가능함
```

이러한 declarations 는 `.ts` 파일이나 `.d.ts` 파일에 포함될 수 있습니다. 실제 프로젝트에서는 이를 `.d.ts` 에 포함시키는 것을 추천합니다. (`globals.d.ts` 나 `vendor.d.ts` 를 보고 시작해보세요)

만약 어떤 파일이 `.d.ts` 라는 확장자를 가졌다면, 모든 루트 레벨의 정의는 `declare` 키워드가 맨 앞에 선언되어야 합니다. 이는 *타입스크립트로부터 영향받는 코드가 없다* 라는 것을 확실하게 해줍니다. 작성자는 선언된 아이템이 런타임에 존재하는지 확인해야 합니다.

> * Ambient declarations 는 컴파일러에게 하는 약속입니다. 만약 런타임 때 해당 아이템이 존재하지 않은 채로 사용하려고 한다면, 경고 없이 프로그램이 망가질 것입니다.
> * Ambient declarations 는 문서와 같습니다. 소스의 변화가 있다면 문서가 업데이트되어야 합니다. 따라서 런타임에서 새로운 동작이 생겼을 때 ambient declaration 을 업데이트하지 않는다면 컴파일 에러가 날 것입니다.


---

# 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/type-system/intro/d.ts.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.
