Skip to content

Commit 802ff13

Browse files
annkimm김민지dvlprsh
authored
feat: translate to Gradual typing #114 (#158)
* feat: translate to Gradual typing * docs: fix text * docs: fix text * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> * Update pages/tutorials/ts-for-functional-programmers.md Co-authored-by: Seohee Park <[email protected]> Co-authored-by: 김민지 <[email protected]> Co-authored-by: Seohee Park <[email protected]>
1 parent 77f21eb commit 802ff13

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

Diff for: β€Žpages/tutorials/ts-for-functional-programmers.md

+77-77
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,59 @@ permalink: /docs/handbook/typescript-in-5-minutes-func.html
55
oneline: Learn TypeScript if you have a background in functional programming
66
---
77

8-
TypeScript began its life as an attempt to bring traditional object-oriented types
9-
to JavaScript so that the programmers at Microsoft could bring
10-
traditional object-oriented programs to the web. As it has developed, TypeScript's type
11-
system has evolved to model code written by native JavaScripters. The
12-
resulting system is powerful, interesting and messy.
8+
TypeScriptλŠ” 웹에 전톡적인 객체 지ν–₯ ν”„λ‘œκ·Έλž¨λ₯Ό κ°€μ Έμ˜€κΈ° μœ„ν•΄μ„œ
9+
λ§ˆμ΄ν¬λ‘œμ†Œν”„νŠΈ ν”„λ‘œκ·Έλž˜λ¨Έλ“€μ΄ JavaScript에 전톡적인 객체 지ν–₯ νƒ€μž…μ„
10+
κ°€μ Έμ˜€κΈ° μœ„ν•œ μ‹œλ„λ‘œ μ‹œμž‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€. κ°œλ°œλ˜μ–΄ κ°€λ©΄μ„œ TypeScript의
11+
νƒ€μž… μ‹œμŠ€ν…œμ€ λ„€μ΄ν‹°λΈŒ μžλ°”μŠ€ν¬λ¦½ν„°κ°€ μž‘μ„±ν•œ λͺ¨λΈ μ½”λ“œλ‘œ λ°œμ „λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
12+
결과적인 μ‹œμŠ€ν…œμ€ κ°•λ ₯ν•˜λ©΄μ„œ ν₯λ―Έλ‘­κ³  μ§€μ €λΆ„ν•©λ‹ˆλ‹€.
1313

14-
This introduction is designed for working Haskell or ML programmers
15-
who want to learn TypeScript. It describes how the type system of
16-
TypeScript differs from Haskell's type system. It also describes
17-
unique features of TypeScript's type system that arise from its
18-
modelling of JavaScript code.
14+
이 μ†Œκ°œλŠ” TypeScriptλ₯Ό 배우고자 ν•˜λŠ” Haskell λ˜λŠ” ML ν”„λ‘œκ·Έλž˜λ¨Έλ₯Ό
15+
μœ„ν•΄ λ§Œλ“€μ–΄μ‘ŒμŠ΅λ‹ˆλ‹€. Haskell νƒ€μž… μ‹œμŠ€ν…œκ³Ό TypeScript νƒ€μž… μ‹œμŠ€ν…œμ˜
16+
차이λ₯Ό μ„€λͺ…ν•©λ‹ˆλ‹€.
17+
λ˜ν•œ JavaScript μ½”λ“œμ˜ λͺ¨λΈλ§μ—μ„œ λ°œμƒν•˜λŠ” TypeScript νƒ€μž… μ‹œμŠ€ν…œμ˜
18+
λ…νŠΉν•œ νŠΉμ§•μ„ μ„€λͺ…ν•©λ‹ˆλ‹€.
1919

20-
This introduction does not cover object-oriented programming. In
21-
practice, object-oriented programs in TypeScript are similar to those
22-
in other popular languages with OO features.
20+
이 μ†Œκ°œμ—μ„œλŠ” 객체 지ν–₯ ν”„λ‘œκ·Έλž˜λ°μ„ 닀루지 μ•ŠμŠ΅λ‹ˆλ‹€.
21+
μ‹€μ œλ‘œ, TypeScript의 객체 지ν–₯ ν”„λ‘œκ·Έλž¨μ€ OO κΈ°λŠ₯이 μžˆλŠ” λ‹€λ₯Έ 인기 μ–Έμ–΄μ˜
22+
ν”„λ‘œκ·Έλž¨κ³Ό μœ μ‚¬ν•©λ‹ˆλ‹€.
2323

24-
# Prerequisites
24+
# μ „μ œμ‘°κ±΄ (Prerequisites)
2525

26-
In this introduction, I assume you know the following:
26+
λ³Έ μ„œλ‘ μ—μ„œλŠ” λ‹€μŒ 사항을 μ•Œκ³  μžˆλ‹€κ³  κ°€μ •ν•©λ‹ˆλ‹€:
2727

28-
* How to program in JavaScript, the good parts.
29-
* Type syntax of a C-descended language.
28+
* JavaScript둜 ν”„λ‘œκ·Έλž˜λ° ν•˜κΈ° μœ„ν•œ 핡심 κ°œλ….
29+
* C 계열 μ–Έμ–΄μ˜ νƒ€μž… ꡬ문.
3030

31-
If you need to learn the good parts of JavaScript, read
32-
[JavaScript: The Good Parts](http://shop.oreilly.com/product/9780596517748.do).
33-
You may be able to skip the book if you know how to write programs in
34-
a call-by-value lexically scoped language with lots of mutability and
35-
not much else.
36-
[R<sup>4</sup>RS Scheme](https://people.csail.mit.edu/jaffer/r4rs.pdf) is a good example.
31+
JavaScript의 핡심 κ°œλ…μ„ 배우고 μ‹Άλ‹€λ©΄
32+
[JavaScript: The Good Parts](http://shop.oreilly.com/product/9780596517748.do)λ₯Ό μΆ”μ²œν•©λ‹ˆλ‹€.
33+
λ§Žμ€ 가변성을 가진 call-by-value λ ‰μ‹œμ»¬ν•œ μŠ€μ½”ν”„ μ–Έμ–΄λ‘œ
34+
ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•˜λŠ” 방법을 μ•Œκ³  μžˆλ‹€λ©΄ ꡳ이 책을 μ•ˆ 읽어도
35+
μƒκ΄€μ—†μŠ΅λ‹ˆλ‹€.
36+
[R<sup>4</sup>RS Scheme](https://people.csail.mit.edu/jaffer/r4rs.pdf)κ°€ 쒋은 μ˜ˆμž…λ‹ˆλ‹€.
3737

38-
[The C++ Programming Language](http://www.stroustrup.com/4th.html) is
39-
a good place to learn about C-style type syntax. Unlike C++,
40-
TypeScript uses postfix types, like so: `x: string` instead of `string x`.
38+
[C++ ν”„λ‘œκ·Έλž˜λ° μ–Έμ–΄](http://www.stroustrup.com/4th.html)λŠ”
39+
C-μŠ€νƒ€μΌ νƒ€μž… ꡬ문에 λŒ€ν•΄μ„œ 배우기 μ’‹μŠ΅λ‹ˆλ‹€.
40+
C++ 달리 TypeScriptλŠ” ν›„μœ„ νƒ€μž…μ„ μ‚¬μš©ν•©λ‹ˆλ‹€, 예λ₯Ό λ“€λ©΄: `string x` λŒ€μ‹ μ— `x: string`.
4141

42-
# Concepts not in Haskell
42+
# Haskellμ—λŠ” μ—†λŠ” κ°œλ… (Concepts not in Haskell)
4343

44-
## Built-in types
44+
## λ‚΄μž₯ νƒ€μž… (Built-in types)
4545

46-
JavaScript defines 7 built-in types:
46+
JavaScriptμ—μ„œλŠ” 7개의 λ‚΄μž₯ νƒ€μž…μ„ μ •μ˜ν•©λ‹ˆλ‹€:
4747

48-
| Type | Explanation |
48+
| νƒ€μž… | μ„€λͺ… |
4949
| ----------- | ------------------------------------------- |
50-
| `Number` | a double-precision IEEE 754 floating point. |
51-
| `String` | an immutable UTF-16 string. |
52-
| `Boolean` | `true` and `false`. |
53-
| `Symbol` | a unique value usually used as a key. |
54-
| `Null` | equivalent to the unit type. |
55-
| `Undefined` | also equivalent to the unit type. |
56-
| `Object` | similar to records. |
50+
| `Number` | 배정밀도 IEEE 754 λΆ€λ™μ†Œμˆ˜μ . |
51+
| `String` | μˆ˜μ • λΆˆκ°€λŠ₯ν•œ UTF-16 λ¬Έμžμ—΄. |
52+
| `Boolean` | `true` 와 `false`. |
53+
| `Symbol` | 보톡 ν‚€λ‘œ μ‚¬μš©ν•˜λŠ” κ³ μœ ν•œ κ°’. |
54+
| `Null` | λ‹¨μœ„ νƒ€μž…κ³Ό 동등. |
55+
| `Undefined` | λ˜ν•œ λ‹¨μœ„ νƒ€μž…κ³Ό 동등. |
56+
| `Object` | λ ˆμ½”λ“œμ™€ μœ μ‚¬ν•œ 것. |
5757

58-
[See the MDN page for more detail](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures).
58+
[μžμ„Έν•œ λ‚΄μš©μ€ MDN νŽ˜μ΄μ§€λ₯Ό μ°Έκ³ ν•˜μ„Έμš”](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures).
5959

60-
TypeScript has corresponding primitive types for the built-in types:
60+
TypeScriptμ—λŠ” κΈ°λ³Έ λ‚΄μž₯된 νƒ€μž…μ— ν•΄λ‹Ήν•˜λŠ” μ›μ‹œ νƒ€μž…μ΄ μžˆμŠ΅λ‹ˆλ‹€:
6161

6262
* `number`
6363
* `string`
@@ -67,84 +67,84 @@ TypeScript has corresponding primitive types for the built-in types:
6767
* `undefined`
6868
* `object`
6969

70-
### Other important TypeScript types
70+
### λ‹€λ₯Έ μ€‘μš”ν•œ TypeScript νƒ€μž… (Other important TypeScript types)
7171

72-
| Type | Explanation |
72+
| νƒ€μž… | μ„€λͺ… |
7373
| -------------- | ----------------------------------------------------------- |
74-
| `unknown` | the top type. |
75-
| `never` | the bottom type. |
76-
| object literal | eg `{ property: Type }` |
77-
| `void` | a subtype of `undefined` intended for use as a return type. |
78-
| `T[]` | mutable arrays, also written `Array<T>` |
79-
| `[T, T]` | tuples, which are fixed-length but mutable |
80-
| `(t: T) => U` | functions |
74+
| `unknown` | μ΅œμƒμœ„ νƒ€μž…. |
75+
| `never` | ν•˜μœ„ νƒ€μž…. |
76+
| 객체 λ¦¬ν„°λŸ΄ | 예, `{ property: Type }` |
77+
| `void` | 리턴 νƒ€μž…μœΌλ‘œ μ‚¬μš©ν•˜κΈ° μœ„ν•΄ μ˜λ„λœ `undefined` 의 μ„œλΈŒνƒ€μž…. |
78+
| `T[]` | μˆ˜μ •κ°€λŠ₯ν•œ λ°°μ—΄λ“€, λ˜ν•œ `Array<T>` 으둜 μ‚¬μš©κ°€λŠ₯ |
79+
| `[T, T]` | κ³ μ •λœ κΈΈμ΄μ§€λ§Œ μˆ˜μ • κ°€λŠ₯ν•œ νŠœν”Œ |
80+
| `(t: T) => U` | ν•¨μˆ˜ |
8181

82-
Notes:
82+
μœ μ˜ν•˜μ„Έμš”:
8383

84-
1. Function syntax includes parameter names. This is pretty hard to get used to!
84+
1. ν•¨μˆ˜ κ΅¬λ¬Έμ—λŠ” λ§€κ°œλ³€μˆ˜ 이름이 ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. μ΅μˆ™ν•΄μ§€κΈ° κ½€ μ–΄λ ΅μŠ΅λ‹ˆλ‹€!
8585

8686
```ts
8787
let fst: (a: any, d: any) => any = (a, d) => a;
88-
// or more precisely:
88+
// λ˜λŠ” μ’€ 더 μ •ν™•ν•˜κ²Œ λ§ν•˜μžλ©΄:
8989
let snd: <T, U>(a: T, d: U) => U = (a, d) => d;
9090
```
9191

92-
2. Object literal type syntax closely mirrors object literal value syntax:
92+
2. 객체 λ¦¬ν„°λŸ΄ νƒ€μž… ꡬ문이 객체 λ¦¬ν„°λŸ΄ κ°’ ꡬ문과 κ½€ μœ μ‚¬ν•©λ‹ˆλ‹€:
9393

9494
```ts
9595
let o: { n: number; xs: object[] } = { n: 1, xs: [] };
9696
```
9797

98-
3. `[T, T]` is a subtype of `T[]`. This is different than Haskell, where tuples are not related to lists.
98+
3. `[T, T]` λŠ” `T[]` 의 μ„œλΈŒνƒ€μž…μž…λ‹ˆλ‹€. Haskellκ³Ό 달리, νŠœν”Œμ€ λ¦¬μŠ€νŠΈμ™€ 관련이 μ—†μŠ΅λ‹ˆλ‹€.
9999

100-
### Boxed types
100+
### λ°•μŠ€ ν˜•νƒœ νƒ€μž… (Boxed types)
101101

102-
JavaScript has boxed equivalents of primitive types that contain the
103-
methods that programmers associate with those types. TypeScript
104-
reflects this with, for example, the difference between the primitive
105-
type `number` and the boxed type `Number`. The boxed types are rarely
106-
needed, since their methods return primitives.
102+
JavaScriptλŠ” ν”„λ‘œκ·Έλž˜λ¨Έλ“€μ΄ ν•΄λ‹Ή νƒ€μž…μ— μ ‘κ·Όν•  수 μžˆλŠ” λ©”μ„œλ“œλ₯Ό
103+
ν¬ν•¨ν•˜λŠ” μ›μ‹œνƒ€μž…μ„ λ™λ“±ν•˜κ²Œ λ°•μŠ€ν•΄ μ™”μŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€λ©΄, μ›μ‹œ ν˜•νƒœμ˜
104+
`number` κ³Ό λ°•μŠ€ ν˜•νƒœ νƒ€μž…μ˜ `Number`의 λ‹€λ₯Έ 점을 TypeScriptλŠ”
105+
λ°˜μ˜ν•΄μ™”μŠ΅λ‹ˆλ‹€.
106+
λ°•μŠ€ ν˜•νƒœ νƒ€μž…μ€ λ©”μ„œλ“œκ°€ μ›μ‹œ νƒ€μž…μ„ λ°˜ν™˜ν•  λ•Œ μ•„μ£Ό λ“œλ¬Όκ²Œ ν•„μš”ν•©λ‹ˆλ‹€.
107107

108108
```ts
109109
(1).toExponential();
110-
// equivalent to
110+
// λ™λ“±ν•˜κ²Œ
111111
Number.prototype.toExponential.call(1);
112112
```
113113

114-
Note that calling a method on a numeric literal requires it to be in
115-
parentheses to aid the parser.
114+
숫자 λ¦¬ν„°λŸ΄μ—μ„œ λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λ €λ©΄ νŒŒμ„œλ₯Ό μ§€μ›ν•˜κΈ° μœ„ν•΄ λ©”μ„œλ“œλ₯Ό κ΄„ν˜Έ
115+
μ•ˆμ— λ„£μ–΄μ•Ό ν•œλ‹€λŠ” 점에 μœ μ˜ν•˜μ‹­μ‹œμ˜€.
116116

117-
## Gradual typing
117+
## 점진적인 타이핑 (Gradual typing)
118118

119-
TypeScript uses the type `any` whenever it can't tell what the type of
120-
an expression should be. Compared to `Dynamic`, calling `any` a type
121-
is an overstatement. It just turns off the type checker
122-
wherever it appears. For example, you can push any value into an
123-
`any[]` without marking the value in any way:
119+
TypeScriptλŠ” ν‘œν˜„μ‹μ˜ νƒ€μž…μ„ μ•Œ 수 없을 λ•Œλ§ˆλ‹€ `any` νƒ€μž…μ„
120+
μ‚¬μš©ν•©λ‹ˆλ‹€. `Dynamic`와 λΉ„κ΅ν•˜λ©΄,`any` λŠ” νƒ€μž…μ΄λΌκ³  λΆ€λ₯΄κΈ°μ—
121+
κ³Όν•˜λ‹€κ³  ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.
122+
이 νƒ€μž…μ΄ λ‚˜νƒ€λ‚  λ•Œλ§ˆλ‹€ νƒ€μž…μ„ μ²΄ν¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, `any[]`
123+
에 μ–΄λ–€ 값이든 μ²΄ν¬ν•˜μ§€ μ•Šκ³  넣어도 μƒκ΄€μ—†μŠ΅λ‹ˆλ‹€:
124124

125-
```ts twoslash
126-
// with "noImplicitAny": false in tsconfig.json, anys: any[]
125+
```ts
126+
// tsconfig.json νŒŒμΌμ— "noImplicitAny": false λ₯Ό μ‚½μž…, anys: any[]
127127
const anys = [];
128128
anys.push(1);
129129
anys.push("oh no");
130130
anys.push({ anything: "goes" });
131131
```
132132

133-
And you can use an expression of type `any` anywhere:
133+
그리고 `any` νƒ€μž…μ€ μ–΄λ””μ„œλ“  간에 μ‚¬μš©κ°€λŠ₯ν•©λ‹ˆλ‹€:
134134

135135
```ts
136-
anys.map(anys[1]); // oh no, "oh no" is not a function
136+
anys.map(anys[1]); // 였 μ•ˆλ˜μ£ , "oh no" ν•¨μˆ˜κ°€ μ•„λ‹™λ‹ˆλ‹€.
137137
```
138138

139-
`any` is contagious, too &mdash; if you initialise a variable with an
140-
expression of type `any`, the variable has type `any` too.
139+
`any` 전염될 수 μžˆλŠ”λ°, μ—­μ‹œ &mdash; λ§Œμ•½μ— `any` νƒ€μž…μ˜ ν‘œν˜„μ‹κ³Ό ν•¨κ»˜ λ³€μˆ˜λ₯Ό μ΄ˆκΈ°ν™”ν•˜λ©΄,
140+
λ³€μˆ˜ μ—­μ‹œ `any` νƒ€μž…μ„ κ°€μ§‘λ‹ˆλ‹€.
141141

142142
```ts
143-
let sepsis = anys[0] + anys[1]; // this could mean anything
143+
let sepsis = anys[0] + anys[1]; // μ–΄λ–€ μ˜λ―Έλ‘œλ„ κ°€λŠ₯ν•©λ‹ˆλ‹€.
144144
```
145145

146-
To get an error when TypeScript produces an `any`, use
147-
`"noImplicitAny": true`, or `"strict": true` in `tsconfig.json`.
146+
TypeScriptλŠ” `any`λ₯Ό μ œκ³΅ν•  λ•Œ μ—λŸ¬κ°€ λ°œμƒλ˜λ©΄,
147+
`tsconfig.json`μ—μ„œ `"noImplicitAny": true` λ˜λŠ” `"strict": true`λ₯Ό μ„€μ •ν•΄μ•Ό ν•©λ‹ˆλ‹€.
148148

149149
## ꡬ쑰적인 타이핑 (Structural typing)
150150

0 commit comments

Comments
Β (0)