Skip to content

Commit 89765e3

Browse files
Literal types issue115 (#139)
* 1์ฐจ ๋ฒˆ์—ญ * ์›๋ฌธ ์‚ญ์ œ, ๋” ๋งค๋„๋Ÿฝ๊ฒŒ ๋ฒˆ์—ญ * ๋งž์ถค๋ฒ• ์ˆ˜์ • * Babel with typescript issue118 (#138) * ์˜์–ด 1์ฐจ ๋ฒˆ์—ญ * ์›๋ฌธ ์‚ญ์ œ, ๋” ๋งค๋„๋Ÿฌ์šด ๋ฒˆ์—ญ์ฒด๋กœ ์ˆ˜์ • * ๋งค๋„๋Ÿฌ์šด ๋ฒˆ์—ญ์ฒด๋กœ ์ถ”๊ฐ€ ์ˆ˜์ • * 1์ฐจ ์ˆ˜์ • * 2์ฐจ ์ˆ˜์ • * 3์ฐจ ์ˆ˜์ • * docs: add seohyun0120 as a contributor (#140) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * 1์ฐจ ๋ฒˆ์—ญ * ์›๋ฌธ ์‚ญ์ œ, ๋” ๋งค๋„๋Ÿฝ๊ฒŒ ๋ฒˆ์—ญ * ๋งž์ถค๋ฒ• ์ˆ˜์ • * ts twoslash๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ œ ์ˆ˜์ • (twoslash ์‚ญ์ œ) * 2์ฐจ ์ˆ˜์ • * contributors ์ •๋ณด ์ˆ˜์ • Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
1 parent aad57cb commit 89765e3

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

Diff for: โ€Ž.all-contributorsrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@
264264
},
265265
{
266266
"login": "seohyun0120",
267-
"name": "Seohyun Yoon",
267+
"name": "SeohyunYoon",
268268
"avatar_url": "https://avatars3.githubusercontent.com/u/35247295?v=4",
269-
"profile": "http://seohyun0120.tistory.com",
269+
"profile": "https://github.com/seohyun0120",
270270
"contributions": [
271271
"translation"
272272
]

Diff for: โ€ŽREADME.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<td align="center"><a href="https://velog.io/@eomttt"><img src="https://avatars2.githubusercontent.com/u/22593217?v=4" width="80px;" alt=""/><br /><sub><b>Hyuntae EOM</b></sub></a><br /><a href="#translation-eomttt" title="Translation">๐ŸŒ</a></td>
6464
<td align="center"><a href="http://samsara-ku.github.io"><img src="https://avatars3.githubusercontent.com/u/59246456?v=4" width="80px;" alt=""/><br /><sub><b>Yunhoe, Ku</b></sub></a><br /><a href="#translation-samsara-ku" title="Translation">๐ŸŒ</a></td>
6565
<td align="center"><a href="https://github.com/realgoways"><img src="https://avatars3.githubusercontent.com/u/15275415?v=4" width="80px;" alt=""/><br /><sub><b>realgo</b></sub></a><br /><a href="#translation-realgoways" title="Translation">๐ŸŒ</a></td>
66-
<td align="center"><a href="http://seohyun0120.tistory.com"><img src="https://avatars3.githubusercontent.com/u/35247295?v=4" width="80px;" alt=""/><br /><sub><b>Seohyun Yoon</b></sub></a><br /><a href="#translation-seohyun0120" title="Translation">๐ŸŒ</a></td>
66+
<td align="center"><a href="https://github.com/seohyun0120"><img src="https://avatars3.githubusercontent.com/u/35247295?v=4" width="80px;" alt=""/><br /><sub><b>SeohyunYoon</b></sub></a><br /><a href="#translation-seohyun0120" title="Translation">๐ŸŒ</a></td>
6767
</tr>
6868
</table>
6969

Diff for: โ€Žpages/literal-types.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ permalink: /docs/handbook/literal-types.html
55
oneline: Using literal types with TypeScript
66
---
77

8-
A literal is a more concrete sub-type of a collective type.
9-
What this means is that `"Hello World"` is a `string`, but a `string` is not `"Hello World"` inside the type system.
8+
๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์€ ์ง‘ํ•ฉ ํƒ€์ž…์˜ ๋ณด๋‹ค ๊ตฌ์ฒด์ ์ธ ํ•˜์œ„ ํƒ€์ž…์ž…๋‹ˆ๋‹ค.
9+
์ด๊ฒƒ์ด ์˜๋ฏธํ•˜๋Š” ๋ฐ”๋Š” ํƒ€์ž… ์‹œ์Šคํ…œ ์•ˆ์—์„œ `"Hello World"`๋Š” `string`์ด์ง€๋งŒ, `string`์€ `"Hello World"`๊ฐ€ ์•„๋‹ˆ๋ž€ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
1010

11-
There are two sets of literal types available in TypeScript today, strings and numbers, by using literal types you can allow an exact value which a string or number must have.
11+
์˜ค๋Š˜๋‚  TypeScript์—๋Š” ๋ฌธ์ž์—ด๊ณผ ์ˆซ์ž, ๋‘ ๊ฐ€์ง€ ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์ด ์žˆ๋Š”๋ฐ ์ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด์ด๋‚˜ ์ˆซ์ž์— ์ •ํ™•ํ•œ ๊ฐ’์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
1212

13-
# Literal Narrowing
13+
# ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž… ์ขํžˆ๊ธฐ (Literal Narrowing)
1414

15-
When you declare a variable via `var` or `let`, you are telling the compiler that there is the chance that this variable will change its contents.
16-
In contrast, using `const` to declare a variable will inform TypeScript that this object will never change.
15+
`var` ๋˜๋Š” `let`์œผ๋กœ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•  ๊ฒฝ์šฐ ์ด ๋ณ€์ˆ˜์˜ ๊ฐ’์ด ๋ณ€๊ฒฝ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์Œ์„ ์ปดํŒŒ์ผ๋Ÿฌ์—๊ฒŒ ์•Œ๋ฆฝ๋‹ˆ๋‹ค.
16+
๋ฐ˜๋ฉด, `const`๋กœ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ฒŒ ๋˜๋ฉด TypeScript์—๊ฒŒ ์ด ๊ฐ์ฒด๋Š” ์ ˆ๋Œ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Œ์„ ์•Œ๋ฆฝ๋‹ˆ๋‹ค.
1717

18-
```ts twoslash
19-
// We're making a guarantee that this variable
20-
// helloWorld will never change, by using const.
18+
```ts
19+
// const๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ€์ˆ˜ helloWorld๊ฐ€
20+
// ์ ˆ๋Œ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Œ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.
2121

22-
// So, TypeScript sets the type to be "Hello World" not string
22+
// ๋”ฐ๋ผ์„œ, TypeScript๋Š” ๋ฌธ์ž์—ด์ด ์•„๋‹Œ "Hello World"๋กœ ํƒ€์ž…์„ ์ •ํ•ฉ๋‹ˆ๋‹ค.
2323
const helloWorld = "Hello World";
2424

25-
// On the other hand, a let can change, and so the compiler declares it a string
25+
// ๋ฐ˜๋ฉด, let์€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ๋ฌธ์ž์—ด์ด๋ผ๊ณ  ์„ ์–ธํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
2626
let hiWorld = "Hi World";
2727
```
2828

29-
The process of going from an infinite number of potential cases (there are an infinite number of possible string values) to a smaller, finite number of potential case (in `helloWorld`'s case: 1) is called narrowing.
29+
๋ฌดํ•œํ•œ ์ˆ˜์˜ ์ž ์žฌ์  ์ผ€์ด์Šค๋“ค (๋ฌธ์ž์—ด ๊ฐ’์€ ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ๋ฌดํ•œ๋Œ€)์„ ์œ ํ•œํ•œ ์ˆ˜์˜ ์ž ์žฌ์  ์ผ€์ด์Šค (`helloWorld`์˜ ๊ฒฝ์šฐ: 1๊ฐœ)๋กœ ์ค„์—ฌ๋‚˜๊ฐ€๋Š” ๊ฒƒ์„ ํƒ€์ž… ์ขํžˆ๊ธฐ (narrowing)๋ผ ํ•œ๋‹ค.
3030

31-
# String Literal Types
31+
# ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž… (String Literal Types)
3232

33-
In practice string literal types combine nicely with union types, type guards, and type aliases.
34-
You can use these features together to get enum-like behavior with strings.
33+
์‹ค์ œ๋กœ ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์€ ์œ ๋‹ˆ์–ธ ํƒ€์ž…, ํƒ€์ž… ๊ฐ€๋“œ ๊ทธ๋ฆฌ๊ณ  ํƒ€์ž… ๋ณ„์นญ๊ณผ ์ž˜ ๊ฒฐํ•ฉ๋ฉ๋‹ˆ๋‹ค.
34+
์ด๋Ÿฐ ๊ธฐ๋Šฅ์„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด๋กœ enum๊ณผ ๋น„์Šทํ•œ ํ˜•ํƒœ๋ฅผ ๊ฐ–์ถœ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
3535

36-
```ts twoslash
36+
```ts
3737
// @errors: 2345
3838
type Easing = "ease-in" | "ease-out" | "ease-in-out";
3939

@@ -44,8 +44,8 @@ class UIElement {
4444
} else if (easing === "ease-out") {
4545
} else if (easing === "ease-in-out") {
4646
} else {
47-
// It's possible that someone could reach this
48-
// by ignoring your types though.
47+
// ํ•˜์ง€๋งŒ ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ ํƒ€์ž…์„ ๋ฌด์‹œํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด
48+
// ์ด๊ณณ์— ๋„๋‹ฌํ•˜๊ฒŒ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
4949
}
5050
}
5151
}
@@ -55,41 +55,41 @@ button.animate(0, 0, "ease-in");
5555
button.animate(0, 0, "uneasy");
5656
```
5757

58-
You can pass any of the three allowed strings, but any other string will give the error
58+
ํ—ˆ์šฉ๋œ ์„ธ ๊ฐœ์˜ ๋ฌธ์ž์—ด์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
5959

6060
```
61-
Argument of type '"uneasy"' is not assignable to parameter of type '"ease-in" | "ease-out" | "ease-in-out"'
61+
'"uneasy"' ํƒ€์ž…์€ '"ease-in" | "ease-out" | "ease-in-out"' ํƒ€์ž…์˜ ๋งค๊ฐœ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
6262
```
6363

64-
String literal types can be used in the same way to distinguish overloads:
64+
๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์€ ์˜ค๋ฒ„๋กœ๋“œ๋ฅผ ๊ตฌ๋ณ„ํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
6565

6666
```ts
6767
function createElement(tagName: "img"): HTMLImageElement;
6868
function createElement(tagName: "input"): HTMLInputElement;
69-
// ... more overloads ...
69+
// ... ์ถ”๊ฐ€์ ์ธ ์ค‘๋ณต ์ •์˜๋“ค ...
7070
function createElement(tagName: string): Element {
71-
// ... code goes here ...
71+
// ... ์—ฌ๊ธฐ์— ๋กœ์ง ์ถ”๊ฐ€ ...
7272
}
7373
```
7474

75-
# Numeric Literal Types
75+
# ์ˆซ์žํ˜• ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž… (Numeric Literal Types)
7676

77-
TypeScript also has numeric literal types, which act the same as the string literals above.
77+
TypeScript์—๋Š” ์œ„์˜ ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด๊ณผ ๊ฐ™์€ ์—ญํ• ์„ ํ•˜๋Š” ์ˆซ์žํ˜• ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
7878

79-
```ts twoslash
79+
```ts
8080
function rollDice(): 1 | 2 | 3 | 4 | 5 | 6 {
8181
return (Math.floor(Math.random() * 6) + 1) as 1 | 2 | 3 | 4 | 5 | 6;
8282
}
8383

8484
const result = rollDice();
8585
```
8686

87-
A common case for their use is for describing config values:
87+
์ด๋Š” ์ฃผ๋กœ ์„ค์ •๊ฐ’์„ ์„ค๋ช…ํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค:
8888

89-
```ts twoslash
90-
/** Creates a map centered at loc/lat */
89+
```ts
90+
/** loc/lat ์ขŒํ‘œ์— ์ง€๋„๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. */
9191
declare function setupMap(config: MapConfig): void;
92-
// ---cut---
92+
// ---์ƒ๋žต---
9393
interface MapConfig {
9494
lng: number;
9595
lat: number;

0 commit comments

Comments
ย (0)