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
Up until now, we haven't told TypeScript what `person`or`date` are.
295
-
Let's edit the code to tell TypeScript that `person` is a `string`, and that `date` should be a `Date`object.
296
-
We'll also use the `toDateString()`method on `date`.
294
+
지금까지는 아직 TypeScript에게 `person`또는`date`가 무엇인지 알려주지 않았습니다.
295
+
코드를 수정하여 TypeScript가 `person`이 `string`이고 `date`가 `Date`객체이어야 한다는 것을 알려주도록 하죠.
296
+
또한 `date`의 `toDateString()`메서드를 사용하겠습니다.
297
297
298
298
```ts twoslash
299
299
function greet(person:string, date:Date) {
300
300
console.log(`Hello ${person}, today is ${date.toDateString()}!`);
301
301
}
302
302
```
303
303
304
-
What we did was add _type annotations_ on `person` and `date` to describe what types of values `greet` can be called with.
305
-
You can read that signature as "`greet` takes a`person` of type `string`, and a `date` of type `Date`".
304
+
방금 우리는 `person`과 `date`에 대하여 _타입 표기_를 수행하여 `greet`가 호출될 때 함께 사용될 수 있는 값들의 타입을 설명했습니다.
305
+
해당 시그니처는 "`greet`는 `string` 타입의`person`과 `Date` 타입의 `date`을 가진다"고 해석할 수 있습니다.
306
306
307
-
With this, TypeScript can tell us about other cases where we might have been called incorrectly.
308
-
For example...
307
+
이것이 있다면, TypeScript는 우리가 해당 함수를 올바르지 못하게 사용했을 경우 이를 알려줄 수 있게 됩니다.
308
+
예를 들어...
309
309
310
310
```ts twoslash
311
311
// @errors: 2345
@@ -316,13 +316,13 @@ function greet(person: string, date: Date) {
316
316
greet("Maddison", Date());
317
317
```
318
318
319
-
Huh?
320
-
TypeScript reported an error on our second argument, but why?
319
+
어?
320
+
TypeScript가 두번째 인자에 대하여 오류를 보고했는데요, 왜 그랬을까요?
321
321
322
-
Perhaps surprisingly, calling`Date()` in JavaScript returns a `string`.
323
-
On the other hand, constructing a `Date` with `new Date()` actually gives us what we were expecting.
322
+
아마도 놀랍게도, JavaScript에서`Date()`를 호출하면 `string`을 반환합니다.
323
+
반면, `new Date()`를 사용하여 `Date` 타입을 생성해야 비로소 처음 기대했던 결과를 반환받을 수 있게 됩니다.
324
324
325
-
Anyway, we can quickly fix up the error:
325
+
어쨌든, 이 오류는 아주 빠르게 고칠 수 있습니다.
326
326
327
327
```ts twoslash {4}
328
328
function greet(person:string, date:Date) {
@@ -332,22 +332,22 @@ function greet(person: string, date: Date) {
332
332
greet("Maddison", newDate());
333
333
```
334
334
335
-
Keep in mind, we don't always have to write explicit type annotations.
336
-
In many cases, TypeScript can even just _infer_ (or "figure out") the types for us even if we omit them.
335
+
명시적인 타입 표기를 항상 작성할 필요는 없다는 것을 꼭 기억해두세요.
336
+
많은 경우, TypeScript는 생략된 타입 정보를 _추론할 수_ (또는 "알아낼 수") 있습니다.
337
337
338
338
```ts twoslash
339
339
let msg ="hello there!";
340
340
// ^?
341
341
```
342
342
343
-
Even though we didn't tell TypeScript that `msg` had the type `string`it was able to figure that out.
344
-
That's a feature, and it's best not to add annotations when the type system would end up inferring the same type anyway.
343
+
`msg`가 `string`타입을 가진다는 사실을 TypeScript에게 알려주지 않았더라도 TypeScript는 이를 알아낼 수 있습니다.
344
+
이는 기본 기능이며, 타입 시스템이 알아서 올바른 타입을 어떻게든 잘 알아낼 수 있다면 타입 표기를 굳이 적지 않는 것이 가장 좋습니다.
345
345
346
-
> Note: the message bubble inside the code sample above. That is what your editor would show if you had hovered over the word.
346
+
> 참고: 바로 위 코드의 말풍선은 에디터에서 해당 코드를 작성했을 때, 해당 변수에 마우스 호버시 화면에 나타나는 내용입니다.
347
347
348
-
## Erased Types
348
+
## 지워진 타입
349
349
350
-
Let's take a look at what happens when we compile the above function `greet` with `tsc` to output JavaScript:
350
+
앞서 작성한 함수 `greet`을 `tsc`로 컴파일하여 JavaScript 출력을 얻었을 때 어떤 일이 일어나는지 보도록 하겠습니다.
351
351
352
352
```ts twoslash
353
353
// @showEmit
@@ -359,17 +359,17 @@ function greet(person: string, date: Date) {
359
359
greet("Maddison", newDate());
360
360
```
361
361
362
-
Notice two things here:
362
+
여기서 두 가지를 알 수 있습니다.
363
363
364
-
1.Our `person` and `date`parameters no longer have type annotations.
365
-
2.Our "template string" - that string that used backticks (the `` ` ``character) - was converted to plain strings with concatenations (`+`).
364
+
1.`person`과 `date`인자는 더 이상 타입 표기를 가지지 않습니다.
365
+
2."템플릿 문자열" - 백틱(`` ` ``문자)을 사용하여 작성된 문장 - 은 연결 연산자(`+`)로 이루어진 일반 문자열로 변환되었습니다.
366
366
367
-
More on that second point later, but let's now focus on that first point.
368
-
Type annotations aren't part of JavaScript (or ECMAScript to be pedantic), so there really aren't any browsers or other runtimes that can just run TypeScript unmodified.
369
-
That's why TypeScript needs a compiler in the first place - it needs some way to strip out or transform any TypeScript-specific code so that you can run it.
370
-
Most TypeScript-specific code gets erased away, and likewise, here our type annotations were completely erased.
367
+
두번째 항목에 대하여서는 이후 자세히 다로도록 하고 우선 첫번째 항목에 초점을 두도록 하겠습니다.
368
+
타입 표기는 JavaScript(또는 엄밀히 말하여 ECMAScript)의 일부가 아니므로, TypeScript를 수정 없이 그대로 실행할 수 있는 브라우저나 런타임을 현재 존재하지 않습니다.
369
+
이것이 TypeScript를 사용하고자 할 때 다른 무엇보다도 컴파일러가 필요한 이유입니다. TypeScript 전용 코드를 제거하거나 변환하여 실행할 수 있도록 만들 방법이 필요합니다.
370
+
TypeScript 전용 코드의 대부분은 제거되며, 마찬가지로 타입 표기 또한 완전히 지워집니다.
371
371
372
-
> **Remember**: Type annotations never change the runtime behavior of your program.
0 commit comments