@@ -5,59 +5,59 @@ permalink: /docs/handbook/typescript-in-5-minutes-func.html
55oneline : 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+ // λλ±νκ²
111111Number .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[]
127127const anys = [];
128128anys .push (1 );
129129anys .push (" oh no" );
130130anys .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