@@ -432,82 +432,82 @@ function height(s: Shape) {
432
432
}
433
433
```
434
434
435
- ## Type Parameters
435
+ ## ํ์
๋งค๊ฐ๋ณ์ ( Type Parameters)
436
436
437
- Like most C-descended languages, TypeScript requires declaration of
438
- type parameters :
437
+ ๋๋ถ๋ถ์ C-๊ณ์ด ์ธ์ด์ฒ๋ผ, TypeScript๋ ํ์
๋งค๊ฐ๋ณ์์ ์ ์ธ์
438
+ ์๊ตฌํฉ๋๋ค :
439
439
440
440
``` ts
441
441
function liftArray<T >(t : T ): Array <T > {
442
442
return [t ];
443
443
}
444
444
```
445
445
446
- There is no case requirement, but type parameters are conventionally
447
- single uppercase letters. Type parameters can also be constrained to a
448
- type, which behaves a bit like type class constraints:
446
+ ๋์๋ฌธ์์ ๋ํ ์๊ตฌ ์กฐ๊ฑด์ ์์ง๋ง, ํ์
๋งค๊ฐ ๋ณ์๋ ์ผ๋ฐ์ ์ผ๋ก ๋จ์ผ ๋๋ฌธ์์
๋๋ค.
447
+ ํ์
๋งค๊ฐ ๋ณ์๋ ํ์
ํด๋์ค ์ ์ฝ๊ณผ ๋น์ทํ๊ฒ ๋์ํ๋
448
+ ํ์
์ผ๋ก ์ ํ๋ ์ ์์ต๋๋ค.
449
449
450
450
``` ts
451
451
function firstish<T extends { length: number }>(t1 : T , t2 : T ): T {
452
452
return t1 .length > t2 .length ? t1 : t2 ;
453
453
}
454
454
```
455
455
456
- TypeScript can usually infer type arguments from a call based on the
457
- type of the arguments, so type arguments are usually not needed .
456
+ TypeScript๋ ์ผ๋ฐ์ ์ผ๋ก ์ธ์ ํ์
์ ๊ธฐ๋ฐํ์ฌ ํธ์ถ๋ก๋ถํฐ ํ์
์ธ์๋ฅผ ์ถ๋ก ํ ์ ์๊ธฐ ๋๋ฌธ์
457
+ ๋๊ฒ ํ์
์ธ์๋ฅผ ํ์๋ก ํ์ง ์์ต๋๋ค .
458
458
459
- Because TypeScript is structural, it doesn't need type parameters as
460
- much as nominal systems. Specifically, they are not needed to make a
461
- function polymorphic. Type parameters should only be used to
462
- _ propagate _ type information, such as constraining parameters to be
463
- the same type :
459
+ ์๋ํ๋ฉด TypeScript๋ ๊ตฌ์กฐ์ ์ด๊ธฐ ๋๋ฌธ์, ์ด๋ฆ ๊ธฐ๋ฐ์ ์์คํ
๋งํผ ํ์
๋งค๊ฐ ๋ณ์๋ฅผ ํ์๋ก
460
+ ํ์ง ์์ต๋๋ค. ํนํ ํจ์๋ฅผ ๋คํ์ฑ์ผ๋ก ๋ง๋ค
461
+ ํ์๋ ์์ต๋๋ค. ํ์
๋งค๊ฐ๋ณ์๋ ๋งค๊ฐ๋ณ์๋ฅผ ๊ฐ์ ํ์
์ผ๋ก
462
+ ์ ํํ๋ ๊ฒ์ฒ๋ผ ํ์
์ ๋ณด๋ฅผ _ ์ ํํ๋๋ฐ๋ง _
463
+ ์ฐ์ฌ์ผ ํฉ๋๋ค :
464
464
465
465
``` ts
466
466
function length<T extends ArrayLike <unknown >>(t : T ): number {}
467
467
468
468
function length(t : ArrayLike <unknown >): number {}
469
469
```
470
470
471
- In the first ` length ` , T is not necessary; notice that it's only
472
- referenced once, so it's not being used to constrain the type of the
473
- return value or other parameters .
471
+ ์ฒซ ๋ฒ์งธ ` length ` ์์ T๋ ํ์ํ์ง ์์ต๋๋ค; ์ค์ง ํ ๋ฒ๋ง ์ฐธ์กฐ๋๋ฉฐ,
472
+ ๋ค๋ฅธ ๋งค๊ฐ๋ณ์๋ ๋ฆฌํด ๊ฐ์ ํ์
์ ์ ํํ๋๋ฐ ์ฌ์ฉ๋์ง ์๋๋ค๋ ๊ฒ์
473
+ ์์๋ฌ์ผ ํฉ๋๋ค .
474
474
475
- ### Higher-kinded types
475
+ ### ์์ ์ ํ์ ํ์
( Higher-kinded types)
476
476
477
- TypeScript does not have higher kinded types, so the following is not legal :
477
+ TypeScript๋ ์์ ์ ํ์ ํ์
์ด ์์ต๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก ๋ค์๊ณผ ๊ฐ์ด ํ๋ ๊ฑด ํ์ฉํ์ง ์์ต๋๋ค :
478
478
479
479
``` ts
480
480
function length<T extends ArrayLike <unknown >, U >(m : T <U >) {}
481
481
```
482
482
483
- ### Point-free programming
483
+ ### ํฌ์ธํธ-ํ๋ฆฌ ํ๋ก๊ทธ๋๋ฐ ( Point-free programming)
484
484
485
- Point-free programming &mdash ; heavy use of currying and function
486
- composition &mdash ; is possible in JavaScript, but can be verbose .
487
- In TypeScript, type inference often fails for point-free programs, so
488
- you'll end up specifying type parameters instead of value parameters. The
489
- result is so verbose that it's usually better to avoid point-free
490
- programming .
485
+ ํฌ์ธํธ-ํ๋ฆฌ ํ๋ก๊ทธ๋๋ฐ์ &mdash ; ์ปค๋ง ๋ฐ ํจ์ ํฉ์ฑ์ ๊ณผ๋ํ ์ฌ์ฉ
486
+ &mdash ; JavaScript์์ ๊ฐ๋ฅํ์ง๋ง ์ฅํฉํ ์ ์์ต๋๋ค .
487
+ TypeScript์์ ํฌ์ธํธ-ํ๋ฆฌ ํ๋ก๊ทธ๋๋ฐ์ ๋ํ ํ์
์ถ๋ก ์ด ์คํจํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ผ๋ฏ๋ก,
488
+ ๊ฐ ๋งค๊ฐ๋ณ์ ๋์ ํ์
๋งค๊ฐ๋ณ์๋ฅผ ์ง์ ํ๊ฒ ๋ฉ๋๋ค.
489
+ ๊ทธ ๊ฒฐ๊ณผ๋ ๋๋ฌด ์ฅํฉํด์ ๋ณดํต ํฌ์ธํธ-ํ๋ฆฌ ํ๋ก๊ทธ๋๋ฐ์ ํผํ๋ ๊ฒ
490
+ ์ข์ต๋๋ค .
491
491
492
- ## Module system
492
+ ## ๋ชจ๋ ์์คํ
( Module system)
493
493
494
- JavaScript's modern module syntax is a bit like Haskell's, except that
495
- any file with ` import ` or ` export ` is implicitly a module :
494
+ ` import ` ๋๋ ` export ` ๊ฐ ํฌํจ๋ ํ์ผ์ด ์์์ ์ผ๋ก ๋ชจ๋์ด๋ผ๋ ์ ์ ์ ์ธํ๋ฉด
495
+ JavaScript์ ์ต์ ๋ชจ๋ ๊ตฌ๋ฌธ์ Haskell๊ณผ ์ฝ๊ฐ ์ ์ฌํฉ๋๋ค :
496
496
497
497
``` ts
498
498
import { value , Type } from " npm-package" ;
499
499
import { other , Types } from " ./local-package" ;
500
500
import * as prefix from " ../lib/third-package" ;
501
501
```
502
502
503
- You can also import commonjs modules &mdash ; modules written using node.js'
504
- module system :
503
+ commonjs ๋ชจ๋๋ก ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค &mdash ; node.js' ๋ชจ๋ ์์คํ
์ผ๋ก
504
+ ์ฌ์ฉ๋ ๋ชจ๋ :
505
505
506
506
``` ts
507
507
import f = require (" single-function-package" );
508
508
```
509
509
510
- You can export with an export list :
510
+ export ๋ชฉ๋ก์ผ๋ก ๋ด๋ณด๋ผ ์ ์์ต๋๋ค :
511
511
512
512
``` ts
513
513
export { f };
@@ -518,29 +518,29 @@ function f() {
518
518
function g() {} // g is not exported
519
519
```
520
520
521
- Or by marking each export individually :
521
+ ๋๋ ๊ฐ๋ณ์ ์ผ๋ก ํ์ํด์ :
522
522
523
523
``` ts
524
524
export function f { return g () }
525
525
function g() { }
526
526
```
527
527
528
- The latter style is more common but both are allowed, even in the same
529
- file .
528
+ ํ์์ ์คํ์ผ์ด ๋ ์ผ๋ฐ์ ์ด์ง๋ง ๊ฐ์ ํ์ผ ๋ด์์๋ ๋ ๋ค
529
+ ํ์ฉ๋ฉ๋๋ค .
530
530
531
- ## ` readonly ` and ` const `
531
+ ## ` readonly ` ์ ` const ` ( ` readonly ` and ` const ` )
532
532
533
- In JavaScript, mutability is the default, although it allows variable
534
- declarations with ` const ` to declare that the _ reference _ is
535
- immutable. The referent is still mutable :
533
+ JavaScript์์, ์์ ๊ฐ๋ฅํจ์ด ๊ธฐ๋ณธ์ด์ง๋ง,
534
+ _ ์ฐธ์กฐ_๊ฐ ์์ ๋ถ๊ฐ๋ฅํจ์ ์ ์ธํ๊ธฐ ์ํด ` const ` ๋ก ๋ณ์๋ฅผ ์ ์ธํ ์ ์์ต๋๋ค.
535
+ ์ฐธ์กฐ ๋์์ ์ฌ์ ํ ์์ ๊ฐ๋ฅํฉ๋๋ค :
536
536
537
537
``` js
538
538
const a = [1 , 2 , 3 ];
539
539
a .push (102 ); // ):
540
540
a[0 ] = 101 ; // D:
541
541
```
542
542
543
- TypeScript additionally has a ` readonly ` modifier for properties .
543
+ TypeScript๋ ์ถ๊ฐ์ ์ผ๋ก ํ๋กํผํฐ์ ` readonly ` ์ ์ด์๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค .
544
544
545
545
``` ts
546
546
interface Rx {
@@ -550,8 +550,8 @@ let rx: Rx = { x: 1 };
550
550
rx .x = 12 ; // error
551
551
```
552
552
553
- It also ships with a mapped type ` Readonly<T> ` that makes
554
- all properties ` readonly ` :
553
+ ๋งคํ๋ ํ์
` Readonly<T> ` ์ ๋ชจ๋ ํ๋กํผํฐ๋ฅผ ` readonly ` ์ผ๋ก
554
+ ๋ง๋ค์ด ๋ฒ๋ฆฝ๋๋ค :
555
555
556
556
``` ts
557
557
interface X {
@@ -561,9 +561,9 @@ let rx: Readonly<X> = { x: 1 };
561
561
rx .x = 12 ; // error
562
562
```
563
563
564
- And it has a specific ` ReadonlyArray<T> ` type that removes
565
- side-affecting methods and prevents writing to indices of the array ,
566
- as well as special syntax for this type :
564
+ ๊ทธ๋ฆฌ๊ณ ๋ถ์์ฉ์ ์ผ์ผํค๋ ๋ฉ์๋๋ฅผ ์ ๊ฑฐํ๊ณ ๋ฐฐ์ด ์ธ๋ฑ์ค์ ๋ํ ๋ณ๊ฒฝ์ ๋ฐฉ์งํ๋
565
+ ํน์ ` ReadonlyArray<T> ` ํ์
๊ณผ ,
566
+ ์ด ํ์
์ ๋ํ ํน์ ๊ตฌ๋ฌธ์ด ์์ต๋๋ค :
567
567
568
568
``` ts
569
569
let a: ReadonlyArray <number > = [1 , 2 , 3 ];
@@ -572,21 +572,21 @@ a.push(102); // error
572
572
b [0 ] = 101 ; // error
573
573
```
574
574
575
- You can also use a const-assertion, which operates on arrays and
576
- object literals :
575
+ ๋ฐฐ์ด๊ณผ ๊ฐ์ฒด ๋ฆฌํฐ๋ด์์ ๋์ํ๋ const-assertion๋ง
576
+ ์ฌ์ฉํ ์ ์์ต๋๋ค :
577
577
578
578
``` ts
579
579
let a = [1 , 2 , 3 ] as const ;
580
580
a .push (102 ); // error
581
581
a [0 ] = 101 ; // error
582
582
```
583
583
584
- However, none of these options are the default, so they are not
585
- consistently used in TypeScript code .
584
+ ๊ทธ๋ฌ๋ ์ด๋ฌํ ๊ธฐ๋ฅ๋ค์ ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋ฅ์ด ์๋๋ฏ๋ก TypeScript ์ฝ๋์
585
+ ์ผ๊ด์ ์ผ๋ก ์ฌ์ฉํ์ง ์์๋ ๋ฉ๋๋ค .
586
586
587
- ## Next Steps
587
+ ## ๋ค์ ๋จ๊ณ ( Next Steps)
588
588
589
- This doc is a high level overview of the syntax and types you would use in everyday code. From here you should :
589
+ ์ด ๋ฌธ์๋ ์ผ์์ ์ธ ์ฝ๋์์ ๋์ ์์ค์ ๊ตฌ๋ฌธ๊ณผ ํ์
์ ๋ํ ๊ฐ์๋ฅผ ๋ด๊ณ ์์ต๋๋ค. ์ฌ๊ธฐ์๋ถํฐ๋ ์๋๋ฅผ ์ฐธ๊ณ ํ์๋ฉด ๋ฉ๋๋ค :
590
590
591
- * -* Read the full Handbook [ from start to finish ] ( /docs/handbook/intro.html ) (30m)
592
- * -* Explore the [ Playground examples ] ( /play#show-examples ) .
591
+ * -* ์ ์ฒด ํธ๋๋ถ์ [ ์ฒ์๋ถํฐ ๋๊น์ง ] ( /docs/handbook/intro.html ) ์ฝ์ผ์ธ์ (30m)
592
+ * -* [ Playground ์์ ] ( /play#show-examples ) ๋ฅผ ๋ณด์ธ์ .
0 commit comments