@@ -293,91 +293,91 @@ let s: "left" | "right" = "right";
293293pad (" hi" , 10 , s );
294294```
295295
296- # Concepts similar to Haskell
296+ # Haskellκ³Ό λΉμ·ν κ°λ
( Concepts similar to Haskell)
297297
298- ## Contextual typing
298+ ## λ¬Έλ§₯μ μΈ νμ΄ν ( Contextual typing)
299299
300- TypeScript has some obvious places where it can infer types, like
301- variable declarations :
300+ TypeScriptλ λ³μ μ μΈκ³Ό κ°μ΄ νμ
μ μΆλ‘ ν μ μλ
301+ λͺ κ°μ§ λΆλͺ
ν λ°©λ²μ΄ μμ΅λλ€ :
302302
303- ``` ts twoslash
303+ ``` ts
304304let s = " I'm a string!" ;
305305```
306306
307- But it also infers types in a few other places that you may not expect
308- if you've worked with other C-syntax languages :
307+ νμ§λ§ λ€λ₯Έ C-κ³μ΄ μΈμ΄λ‘ μμ
ν μ μ΄ μλ€λ©΄ μμνμ§ λͺ»νλ
308+ λ€λ₯Έ λ°©λ²μΌλ‘ νμ
μΆλ‘ μ΄ κ°λ₯ν©λλ€ :
309309
310- ``` ts twoslash
310+ ``` ts
311311declare function map<T , U >(f : (t : T ) => U , ts : T []): U [];
312312let sns = map ((n ) => n .toString (), [1 , 2 , 3 ]);
313313```
314314
315- Here, ` n: number ` in this example also, despite the fact that ` T ` and ` U `
316- have not been inferred before the call. In fact, after ` [1,2,3] ` has
317- been used to infer ` T=number ` , the return type of ` n => n.toString() `
318- is used to infer ` U=string ` , causing ` sns ` to have the type
319- ` string[] ` .
315+ μ¬κΈ°μμ, μ΄ μμμ ` n: number ` μμ λν, ` T ` κ³Ό ` U ` λ νΈμΆ μ μ
316+ μΆλ‘ λμ§ μμμμλ λΆκ΅¬νκ³ .
317+ μ€μ λ‘ ` [1,2,3] ` μΌλ‘ ` T=number ` μ μΆλ‘ ν λ€μμ,
318+ ` n => n.toString() ` μ λ¦¬ν΄ νμ
μΌλ‘ ` U=string ` μ μΆλ‘ νμ¬,
319+ ` sns ` κ° ` string[] ` νμ
μ κ°μ§λλ‘ ν©λλ€ .
320320
321- Note that inference will work in any order, but intellisense will only
322- work left-to-right, so TypeScript prefers to declare ` map ` with the
323- array first :
321+ μΆλ‘ μ μ΄λ€ μμλ‘λ μλνμ§λ§, intellisenseλ μΌμͺ½μμ μ€λ₯Έμͺ½μΌλ‘λ§
322+ μλνλ―λ‘, TypeScriptλ λ°°μ΄κ³Ό ν¨κ» ` map ` μ λ¨Όμ μ μΈνλ κ²μ
323+ μ νΈν©λλ€ :
324324
325- ``` ts twoslash
325+ ``` ts
326326declare function map<T , U >(ts : T [], f : (t : T ) => U ): U [];
327327```
328328
329- Contextual typing also works recursively through object literals, and
330- on unit types that would otherwise be inferred as ` string ` or
331- ` number ` . And it can infer return types from context :
329+ λ¬Έλ§₯μ μΈ νμ΄νμ λν κ°μ²΄ 리ν°λ΄μ ν΅ν΄ μ¬κ·μ μΌλ‘ μλνλ©°, κ·Έλ μ§ μμΌλ©΄
330+ ` string ` μ΄λ ` number ` λ‘ μΆλ‘ κ°λ₯ν μ λ νμ
μΌλ‘ μλν©λλ€.
331+ κ·Έλ¦¬κ³ λ¬Έλ§₯μ ν΅ν΄μ λ¦¬ν΄ νμ
μ μΆλ‘ ν μ μμ΅λλ€ :
332332
333- ``` ts twoslash
333+ ``` ts
334334declare function run<T >(thunk : (t : T ) => void ): T ;
335335let i: { inference: string } = run ((o ) => {
336336 o .inference = " INSERT STATE HERE" ;
337337});
338338```
339339
340- The type of ` o ` is determined to be ` { inference: string } ` because
340+ ` o ` μ νμ
μ ` { inference: string } ` μΌλ‘ κ²°μ λμμ΅λλ€. μλνλ©΄
341341
342- 1 . Declaration initialisers are contextually typed by the
343- declaration's type: ` { inference: string } ` .
344- 2 . The return type of a call uses the contextual type for inferences ,
345- so the compiler infers that ` T={ inference: string } ` .
346- 3 . Arrow functions use the contextual type to type their parameters ,
347- so the compiler gives ` o: { inference: string } ` .
342+ 1 . μ μΈ μ΄λμ
λΌμ΄μ λ μ μΈ νμ
: ` { inference: string } ` μ λ°λΌμ
343+ λ¬Έλ§₯μ μΌλ‘ νμ
μ΄ μ ν΄μ§λλ€ .
344+ 2 . νΈμΆμ λ¦¬ν΄ νμ
μ μΆλ‘ μ μν΄ λ¬Έλ§₯μ μΈ νμ
μ μ¬μ©νκΈ° λλ¬Έμ ,
345+ μ»΄νμΌλ¬λ ` T={ inference: string } ` μΌλ‘ μΆλ‘ ν©λλ€ .
346+ 3 . νμ΄ν ν¨μλ λ§€κ°λ³μμ νμ
μ μ§μ νκΈ° μν΄ λ¬Έλ§₯μ μΈ νμ
μ μ¬μ©νλ―λ‘ ,
347+ μ»΄νμΌλ¬λ ` o: { inference: string } ` λ₯Ό μ 곡ν©λλ€ .
348348
349- And it does so while you are typing, so that after typing ` o. ` , you
350- get completions for the property ` inference ` , along with any other
351- properties you'd have in a real program .
352- Altogether, this feature can make TypeScript's inference look a bit
353- like a unifying type inference engine, but it is not .
349+ μ
λ ₯νλ λμ, ` o. ` λ₯Ό νμ΄ν νμ,
350+ μ€μ νλ‘κ·Έλ¨μ μλ λ€λ₯Έ μμ±κ³Ό ν¨κ» μμ± ` inference ` μΌλ‘
351+ 보μν μ μμ΅λλ€ .
352+ μ΄ κΈ°λ₯μ TypeScriptμ μΆλ‘ μ ν΅ν΄ ν΅ν©μ μΈ νμ
μΆλ‘ μμ§μ²λΌ
353+ 보μ΄κ² μ§λ§, κ·Έλ μ§ μμ΅λλ€ .
354354
355- ## Type aliases
355+ ## νμ
λ³μΉ ( Type aliases)
356356
357- Type aliases are mere aliases, just like ` type ` in Haskell. The
358- compiler will attempt to use the alias name wherever it was used in
359- the source code, but does not always succeed .
357+ νμ
λ³μΉμ Haskellμ ` type ` κ³Ό λ§μ°¬κ°μ§λ‘ λ¨μν λ³μΉμ
λλ€.
358+ μ»΄νμΌλ¬λ μμ€ μ½λμμ μ¬μ©λ λ³μΉ μ΄λ¦μ μ¬μ©νλ €κ³
359+ μλνμ§λ§ νμ μ±κ³΅νμ§λ μμ΅λλ€ .
360360
361- ``` ts twoslash
361+ ``` ts
362362type Size = [number , number ];
363363let x: Size = [101.1 , 999.9 ];
364364```
365365
366- The closest equivalent to ` newtype ` is a _ tagged intersection _ :
366+ ` newtype ` κ³Ό κ°μ₯ μ μ¬ν κ²μ _ νκ·Έλ κ΅μ°¨ νμ
(tagged intersection) _ μ
λλ€ :
367367
368368``` ts
369369type FString = string & { __compileTimeOnly: any };
370370```
371371
372- An ` FString ` is just like a normal string, except that the compiler
373- thinks it has a property named ` __compileTimeOnly ` that doesn't
374- actually exist. This means that ` FString ` can still be assigned to
375- ` string ` , but not the other way round .
372+ ` FString ` μ μ»΄νμΌλ¬κ° μ€μ λ‘λ μ‘΄μ¬νμ§ μλ ` __compileTimeOnly ` λΌλ
373+ νλ‘νΌν°λ₯Ό κ°μ§κ³ μλ€κ³ μκ°νλ μ μ μ μΈνλ©΄ μΌλ° λ¬Έμμ΄κ³Ό κ°μ΅λλ€.
374+ ` FString ` μ μ¬μ ν ` string ` μ ν λΉ κ°λ₯νμ§λ§,
375+ κ·Έ λ°λλ λΆκ°λ₯νλ€λ κ²μ μλ―Έν©λλ€ .
376376
377- ## Discriminated Unions
377+ ## νλ³ μ λμΈ ( Discriminated Unions)
378378
379- The closest equivalent to ` data ` is a union of types with discriminant
380- properties, normally called discriminated unions in TypeScript :
379+ ` data ` μ κ°μ₯ μ μ¬ν κ²μ λ³΄ν΅ TypeScriptμμ νλ³ μ λμΈμ΄λΌ λΆλ¦¬λ,
380+ νλ³ νλ‘νΌν°λ₯Ό κ°λ νμ
μ μ λμΈμ
λλ€ :
381381
382382``` ts
383383type Shape =
@@ -386,13 +386,13 @@ type Shape =
386386 | { kind: " triangle" ; x: number ; y: number };
387387```
388388
389- Unlike Haskell, the tag, or discriminant, is just a property in each
390- object type. Each variant has an identical property with a different
391- unit type. This is still a normal union type; the leading ` | ` is
392- an optional part of the union type syntax. You can discriminate the
393- members of the union using normal JavaScript code :
389+ νμ€μΌκ³Ό λ¬λ¦¬, νκ·Έ λλ νλ³μ κ°κ° κ°μ²΄ νμ
μμ λ¨μ§ μμ±μ λΆκ΅¬ν©λλ€.
390+ νΉμ΄ μΌμ΄μ€λ λ€λ₯Έ μ λ νμ
κ³Ό ν¨κ» λμΌν μμ±μ κ°μ§λλ€.
391+ μμ§ νλ²ν μ λμΈνμ
μ
λλ€; 리λνλ ` | ` λ
392+ μ λμΈ νμ
ꡬ문μ μ νμ μΈ λΆλΆμ
λλ€. μ λμΈμ μ¬μ©νλ νλ²ν JavaScript
393+ μ½λλ‘ κ΅¬λ³κ°λ₯ν©λλ€ :
394394
395- ``` ts twoslash
395+ ``` ts
396396type Shape =
397397 | { kind: " circle" ; radius: number }
398398 | { kind: " square" ; x: number }
@@ -409,14 +409,14 @@ function area(s: Shape) {
409409}
410410```
411411
412- Note that the return type of ` area ` is inferred to be ` number ` because
413- TypeScript knows the function is total. If some variant is not
414- covered, the return type of ` area ` will be ` number | undefined ` instead .
412+ ` area ` μ λ¦¬ν΄ νμ
μ ` number ` λ₯Ό λνλ΄λλ°, TypeScriptκ° ν¨μκ° μ 체λΌλ
413+ κ±Έ μκ³ μκΈ° λλ¬Έμ μ μν΄μΌν νμκ° μμ΅λλ€. λͺλͺ νΉμ΄ μΌμ΄μ€κ° 컀λ²λμ§ μμΌλ©΄
414+ ` area ` μ λ¦¬ν΄ νμ
μ ` number | undefined ` μΌλ‘ λμ λ κ²μ
λλ€ .
415415
416- Also, unlike Haskell, common properties show up in any union, so you
417- can usefully discriminate multiple members of the union :
416+ λν, νμ€μΌκ³Ό λ¬λ¦¬ νν μμ±λ€μ μ΄λ€ μ λμΈμλ λνλλ©°,
417+ κ·Έλμ μ μ©νκ² μ¬λ¬ κ°μ μ λμΈ κ΅¬λΆκ°λ₯ν©λλ€ :
418418
419- ``` ts twoslash
419+ ``` ts
420420type Shape =
421421 | { kind: " circle" ; radius: number }
422422 | { kind: " square" ; x: number }
@@ -589,4 +589,4 @@ a[0] = 101; // error
589589μ΄ λ¬Έμλ μΌμμ μΈ μ½λμμ λμ μμ€μ ꡬ문과 νμ
μ λν κ°μλ₯Ό λ΄κ³ μμ΅λλ€. μ¬κΈ°μλΆν°λ μλλ₯Ό μ°Έκ³ νμλ©΄ λ©λλ€:
590590
591591* -* μ 체 νΈλλΆμ [ μ²μλΆν° λκΉμ§] ( /docs/handbook/intro.html ) μ½μΌμΈμ (30m)
592- * -* [ Playground μμ] ( /play#show-examples ) λ₯Ό 보μΈμ.
592+ * -* [ Playground μμ] ( /play#show-examples ) λ₯Ό 보μΈμ.
0 commit comments