You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can tell TypeScript that you are trying to describe code that exists elsewhere (e.g. written in JavaScript/CoffeeScript/The runtime environment like the browser or Node.js) using the `declare`keyword. As a quick example:
2
+
다른 곳에 존재하는(e.g. 자바스크립트/커피스크립트/브라우저/Node 등등) 자바스크립트코드를 설명하기 위해 Typescript 에서는 `declare`라는 키워드를 쓸 수 있습니다. 간단한 예제를 살펴보면:
3
3
4
4
```ts
5
-
foo=123; //Error: `foo` is not defined
5
+
foo=123; //에러: `foo` is not defined
6
6
```
7
7
vs.
8
8
```ts
9
9
declarevar foo:any;
10
-
foo=123; //allowed
10
+
foo=123; //가능함
11
11
```
12
12
13
-
You have the option of putting these declarations in a `.ts`file or in a `.d.ts`file. We highly recommend that in your real world projects you use a separate `.d.ts`(start with one called something like `globals.d.ts`or`vendor.d.ts`).
13
+
이러한 declarations 는 `.ts`파일이나 `.d.ts`파일에 포함될 수 있습니다. 실제 프로젝트에서는 이를 `.d.ts`에 포함시키는 것을 추천합니다. (`globals.d.ts`나`vendor.d.ts` 를 보고 시작해보세요)
14
14
15
-
If a file has the extension `.d.ts`then each root level definition must have the `declare`keyword prefixed to it. This helps make it clear to the author that there will be *no code emitted by TypeScript*. The author needs to ensure that the declared item will exist at runtime.
15
+
만약 어떤 파일이 `.d.ts`라는 확장자를 가졌다면, 모든 루트 레벨의 정의는 `declare`키워드가 맨 앞에 선언되어야 합니다. 이는 *타입스크립트로부터 영향받는 코드가 없다* 라는 것을 확실하게 해줍니다. 작성자는 선언된 아이템이 런타임에 존재하는지 확인해야 합니다.
16
16
17
-
> * Ambient declarations is a promise that you are making with the compiler. If these do not exist at runtime and you try to use them, things will break without warning.
18
-
* Ambient declarations are like docs. If the source changes the docs need to be kept updated. So you might have new behaviours that work at runtime but no one's updated the ambient declaration and hence you get compiler errors.
17
+
> * Ambient declarations 는 컴파일러에게 하는 약속입니다. 만약 런타임 때 해당 아이템이 존재하지 않은 채로 사용하려고 한다면, 경고 없이 프로그램이 망가질 것입니다.
18
+
* Ambient declarations 는 문서와 같습니다. 소스의 변화가 있다면 문서가 업데이트되어야 합니다. 따라서 런타임에서 새로운 동작이 생겼을 때 ambient declaration 을 업데이트하지 않는다면 컴파일 에러가 날 것입니다.
As we mentioned in [why TypeScript](../../why-typescript.md):
3
+
[왜 타입스크립트인가?](../../why-typescript.md) 에서 언급했듯이:
4
4
5
-
> A major design goal of TypeScript was to make it possible for you to safely and easily use existing JavaScript libraries in TypeScript. TypeScript does this by means of *declaration*.
5
+
> 타입스크립트 설계의 주 목적 중 하나는 자바스크립트 라이브러리들을 타입스크립트에서 안전하고 쉽게 사용할 수 있게 하는 것입니다. 타입스크립트에서 *declaration* 이 그 역할을 합니다.
6
6
7
-
Ambient declarations allow you to *safely use existing popular JavaScript libraries* and *incrementally migrate your JavaScript/CoffeeScript/Other-Compile-To-Js-Language project to TypeScript*.
7
+
Ambient declarations 는 *유명한 자바스크립트 라이브러리들을 쉽게 사용할 수 있게* 하고, *자바스크립트/커피스크립트/자바스크립트로 컴파일 될 수 있는 다른 언어 로 만들어진 라이브러리를 타입스크립트로 점진적으로 마이그레이션 할 수 있게* 합니다.
8
8
9
-
Studying patterns in ambient declarations for *third party JavaScript code* is good practice for annotating *your* TypeScript code base as well. This is why we present it so early on.
9
+
*써드 파티 자바스크립트 코드* 의 ambient declaration 을 공부하는 것은 *당신의* 타입스크립트 코드베이스에 를 위한 연습이 될 수 있습니다. 이것이 우리가 Ambient Declarations 를 일찍 소개하는 이유입니다.
For example to tell TypeScript about the [`process`variable](https://nodejs.org/api/process.html)you *can* do:
2
+
예를 들어 타입스크립트에게 [`process`변수](https://nodejs.org/api/process.html)에 대해 알려주기 위해 이렇게 할 수 있습니다:
3
3
4
4
```ts
5
5
declarevar process:any;
6
6
```
7
7
8
-
> You don't *need* to do this for `process` as there is already a [community maintained `node.d.ts`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts).
8
+
> 하지만 [커뮤니티에서 `node.d.ts` 를 관리하고 있기 때문에](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts)`process` 에 대해서 이런 식으로 정의할 필요가 없습니다.
9
9
10
-
This allows you to use the `process` variable without TypeScript complaining:
10
+
따라서 `process` 변수를 Typescript 에서 따로 선언하지 않고 사용할 수 있습니다:
11
11
12
12
```ts
13
13
process.exit();
14
14
```
15
15
16
-
We recommend using an interface wherever possible e.g.:
16
+
우리는 아래와 같이 interface 를 쓰는 것을 추천합니다:
17
17
18
18
```ts
19
19
interfaceProcess {
@@ -22,7 +22,7 @@ interface Process {
22
22
declarevar process:Process;
23
23
```
24
24
25
-
This allows other people to *extend*the nature of these global variables while still telling TypeScript about such modifications. E.g. consider the following case where we add an `exitWithLogging`function to process for our amusement:
25
+
이는 글로벌 변수들을 *extend*할 수 있게 하면서도, 타입스크립트가 글로벌 변수의 변경사항에 대해 알 수 있게 합니다. 예를 들어, 다음의 예제는 필요에 의해 process 에 `exitWithLogging`함수를 추가한 예제입니다:
0 commit comments