-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1219 lines (1054 loc) · 59.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Typescript</title><style>
/* cspell:disable-file */
/* webkit printing magic: print all background colors */
html {
-webkit-print-color-adjust: exact;
}
* {
box-sizing: border-box;
-webkit-print-color-adjust: exact;
}
html,
body {
margin: 0;
padding: 0;
}
@media only screen {
body {
margin: 2em auto;
max-width: 900px;
color: rgb(55, 53, 47);
}
}
body {
line-height: 1.5;
white-space: pre-wrap;
}
a,
a.visited {
color: inherit;
text-decoration: underline;
}
.pdf-relative-link-path {
font-size: 80%;
color: #444;
}
h1,
h2,
h3 {
letter-spacing: -0.01em;
line-height: 1.2;
font-weight: 600;
margin-bottom: 0;
}
.page-title {
font-size: 2.5rem;
font-weight: 700;
margin-top: 0;
margin-bottom: 0.75em;
}
h1 {
font-size: 1.875rem;
margin-top: 1.875rem;
}
h2 {
font-size: 1.5rem;
margin-top: 1.5rem;
}
h3 {
font-size: 1.25rem;
margin-top: 1.25rem;
}
.source {
border: 1px solid #ddd;
border-radius: 3px;
padding: 1.5em;
word-break: break-all;
}
.callout {
border-radius: 3px;
padding: 1rem;
}
figure {
margin: 1.25em 0;
page-break-inside: avoid;
}
figcaption {
opacity: 0.5;
font-size: 85%;
margin-top: 0.5em;
}
mark {
background-color: transparent;
}
.indented {
padding-left: 1.5em;
}
hr {
background: transparent;
display: block;
width: 100%;
height: 1px;
visibility: visible;
border: none;
border-bottom: 1px solid rgba(55, 53, 47, 0.09);
}
img {
max-width: 100%;
}
@media only print {
img {
max-height: 100vh;
object-fit: contain;
}
}
@page {
margin: 1in;
}
.collection-content {
font-size: 0.875rem;
}
.column-list {
display: flex;
justify-content: space-between;
}
.column {
padding: 0 1em;
}
.column:first-child {
padding-left: 0;
}
.column:last-child {
padding-right: 0;
}
.table_of_contents-item {
display: block;
font-size: 0.875rem;
line-height: 1.3;
padding: 0.125rem;
}
.table_of_contents-indent-1 {
margin-left: 1.5rem;
}
.table_of_contents-indent-2 {
margin-left: 3rem;
}
.table_of_contents-indent-3 {
margin-left: 4.5rem;
}
.table_of_contents-link {
text-decoration: none;
opacity: 0.7;
border-bottom: 1px solid rgba(55, 53, 47, 0.18);
}
table,
th,
td {
border: 1px solid rgba(55, 53, 47, 0.09);
border-collapse: collapse;
}
table {
border-left: none;
border-right: none;
}
th,
td {
font-weight: normal;
padding: 0.25em 0.5em;
line-height: 1.5;
min-height: 1.5em;
text-align: left;
}
th {
color: rgba(55, 53, 47, 0.6);
}
ol,
ul {
margin: 0;
margin-block-start: 0.6em;
margin-block-end: 0.6em;
}
li > ol:first-child,
li > ul:first-child {
margin-block-start: 0.6em;
}
ul > li {
list-style: disc;
}
ul.to-do-list {
padding-inline-start: 0;
}
ul.to-do-list > li {
list-style: none;
}
.to-do-children-checked {
text-decoration: line-through;
opacity: 0.375;
}
ul.toggle > li {
list-style: none;
}
ul {
padding-inline-start: 1.7em;
}
ul > li {
padding-left: 0.1em;
}
ol {
padding-inline-start: 1.6em;
}
ol > li {
padding-left: 0.2em;
}
.mono ol {
padding-inline-start: 2em;
}
.mono ol > li {
text-indent: -0.4em;
}
.toggle {
padding-inline-start: 0em;
list-style-type: none;
}
/* Indent toggle children */
.toggle > li > details {
padding-left: 1.7em;
}
.toggle > li > details > summary {
margin-left: -1.1em;
}
.selected-value {
display: inline-block;
padding: 0 0.5em;
background: rgba(206, 205, 202, 0.5);
border-radius: 3px;
margin-right: 0.5em;
margin-top: 0.3em;
margin-bottom: 0.3em;
white-space: nowrap;
}
.collection-title {
display: inline-block;
margin-right: 1em;
}
.page-description {
margin-bottom: 2em;
}
.simple-table {
margin-top: 1em;
font-size: 0.875rem;
empty-cells: show;
}
.simple-table td {
height: 29px;
min-width: 120px;
}
.simple-table th {
height: 29px;
min-width: 120px;
}
.simple-table-header-color {
background: rgb(247, 246, 243);
color: black;
}
.simple-table-header {
font-weight: 500;
}
time {
opacity: 0.5;
}
.icon {
display: inline-block;
max-width: 1.2em;
max-height: 1.2em;
text-decoration: none;
vertical-align: text-bottom;
margin-right: 0.5em;
}
img.icon {
border-radius: 3px;
}
.user-icon {
width: 1.5em;
height: 1.5em;
border-radius: 100%;
margin-right: 0.5rem;
}
.user-icon-inner {
font-size: 0.8em;
}
.text-icon {
border: 1px solid #000;
text-align: center;
}
.page-cover-image {
display: block;
object-fit: cover;
width: 100%;
max-height: 30vh;
}
.page-header-icon {
font-size: 3rem;
margin-bottom: 1rem;
}
.page-header-icon-with-cover {
margin-top: -0.72em;
margin-left: 0.07em;
}
.page-header-icon img {
border-radius: 3px;
}
.link-to-page {
margin: 1em 0;
padding: 0;
border: none;
font-weight: 500;
}
p > .user {
opacity: 0.5;
}
td > .user,
td > time {
white-space: nowrap;
}
input[type="checkbox"] {
transform: scale(1.5);
margin-right: 0.6em;
vertical-align: middle;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.image {
border: none;
margin: 1.5em 0;
padding: 0;
border-radius: 0;
text-align: center;
}
.code,
code {
background: rgba(135, 131, 120, 0.15);
border-radius: 3px;
padding: 0.2em 0.4em;
border-radius: 3px;
font-size: 85%;
tab-size: 2;
}
code {
color: #eb5757;
}
.code {
padding: 1.5em 1em;
}
.code-wrap {
white-space: pre-wrap;
word-break: break-all;
}
.code > code {
background: none;
padding: 0;
font-size: 100%;
color: inherit;
}
blockquote {
font-size: 1.25em;
margin: 1em 0;
padding-left: 1em;
border-left: 3px solid rgb(55, 53, 47);
}
.bookmark {
text-decoration: none;
max-height: 8em;
padding: 0;
display: flex;
width: 100%;
align-items: stretch;
}
.bookmark-title {
font-size: 0.85em;
overflow: hidden;
text-overflow: ellipsis;
height: 1.75em;
white-space: nowrap;
}
.bookmark-text {
display: flex;
flex-direction: column;
}
.bookmark-info {
flex: 4 1 180px;
padding: 12px 14px 14px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.bookmark-image {
width: 33%;
flex: 1 1 180px;
display: block;
position: relative;
object-fit: cover;
border-radius: 1px;
}
.bookmark-description {
color: rgba(55, 53, 47, 0.6);
font-size: 0.75em;
overflow: hidden;
max-height: 4.5em;
word-break: break-word;
}
.bookmark-href {
font-size: 0.75em;
margin-top: 0.25em;
}
.sans { font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"; }
.code { font-family: "SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace; }
.serif { font-family: Lyon-Text, Georgia, ui-serif, serif; }
.mono { font-family: iawriter-mono, Nitti, Menlo, Courier, monospace; }
.pdf .sans { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol", 'Twemoji', 'Noto Color Emoji', 'Noto Sans CJK JP'; }
.pdf:lang(zh-CN) .sans { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol", 'Twemoji', 'Noto Color Emoji', 'Noto Sans CJK SC'; }
.pdf:lang(zh-TW) .sans { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol", 'Twemoji', 'Noto Color Emoji', 'Noto Sans CJK TC'; }
.pdf:lang(ko-KR) .sans { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol", 'Twemoji', 'Noto Color Emoji', 'Noto Sans CJK KR'; }
.pdf .code { font-family: Source Code Pro, "SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK JP'; }
.pdf:lang(zh-CN) .code { font-family: Source Code Pro, "SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK SC'; }
.pdf:lang(zh-TW) .code { font-family: Source Code Pro, "SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK TC'; }
.pdf:lang(ko-KR) .code { font-family: Source Code Pro, "SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK KR'; }
.pdf .serif { font-family: PT Serif, Lyon-Text, Georgia, ui-serif, serif, 'Twemoji', 'Noto Color Emoji', 'Noto Serif CJK JP'; }
.pdf:lang(zh-CN) .serif { font-family: PT Serif, Lyon-Text, Georgia, ui-serif, serif, 'Twemoji', 'Noto Color Emoji', 'Noto Serif CJK SC'; }
.pdf:lang(zh-TW) .serif { font-family: PT Serif, Lyon-Text, Georgia, ui-serif, serif, 'Twemoji', 'Noto Color Emoji', 'Noto Serif CJK TC'; }
.pdf:lang(ko-KR) .serif { font-family: PT Serif, Lyon-Text, Georgia, ui-serif, serif, 'Twemoji', 'Noto Color Emoji', 'Noto Serif CJK KR'; }
.pdf .mono { font-family: PT Mono, iawriter-mono, Nitti, Menlo, Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK JP'; }
.pdf:lang(zh-CN) .mono { font-family: PT Mono, iawriter-mono, Nitti, Menlo, Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK SC'; }
.pdf:lang(zh-TW) .mono { font-family: PT Mono, iawriter-mono, Nitti, Menlo, Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK TC'; }
.pdf:lang(ko-KR) .mono { font-family: PT Mono, iawriter-mono, Nitti, Menlo, Courier, monospace, 'Twemoji', 'Noto Color Emoji', 'Noto Sans Mono CJK KR'; }
.highlight-default {
color: rgba(55, 53, 47, 1);
}
.highlight-gray {
color: rgba(120, 119, 116, 1);
fill: rgba(120, 119, 116, 1);
}
.highlight-brown {
color: rgba(159, 107, 83, 1);
fill: rgba(159, 107, 83, 1);
}
.highlight-orange {
color: rgba(217, 115, 13, 1);
fill: rgba(217, 115, 13, 1);
}
.highlight-yellow {
color: rgba(203, 145, 47, 1);
fill: rgba(203, 145, 47, 1);
}
.highlight-teal {
color: rgba(68, 131, 97, 1);
fill: rgba(68, 131, 97, 1);
}
.highlight-blue {
color: rgba(51, 126, 169, 1);
fill: rgba(51, 126, 169, 1);
}
.highlight-purple {
color: rgba(144, 101, 176, 1);
fill: rgba(144, 101, 176, 1);
}
.highlight-pink {
color: rgba(193, 76, 138, 1);
fill: rgba(193, 76, 138, 1);
}
.highlight-red {
color: rgba(212, 76, 71, 1);
fill: rgba(212, 76, 71, 1);
}
.highlight-gray_background {
background: rgba(241, 241, 239, 1);
}
.highlight-brown_background {
background: rgba(244, 238, 238, 1);
}
.highlight-orange_background {
background: rgba(251, 236, 221, 1);
}
.highlight-yellow_background {
background: rgba(251, 243, 219, 1);
}
.highlight-teal_background {
background: rgba(237, 243, 236, 1);
}
.highlight-blue_background {
background: rgba(231, 243, 248, 1);
}
.highlight-purple_background {
background: rgba(244, 240, 247, 0.8);
}
.highlight-pink_background {
background: rgba(249, 238, 243, 0.8);
}
.highlight-red_background {
background: rgba(253, 235, 236, 1);
}
.block-color-default {
color: inherit;
fill: inherit;
}
.block-color-gray {
color: rgba(120, 119, 116, 1);
fill: rgba(120, 119, 116, 1);
}
.block-color-brown {
color: rgba(159, 107, 83, 1);
fill: rgba(159, 107, 83, 1);
}
.block-color-orange {
color: rgba(217, 115, 13, 1);
fill: rgba(217, 115, 13, 1);
}
.block-color-yellow {
color: rgba(203, 145, 47, 1);
fill: rgba(203, 145, 47, 1);
}
.block-color-teal {
color: rgba(68, 131, 97, 1);
fill: rgba(68, 131, 97, 1);
}
.block-color-blue {
color: rgba(51, 126, 169, 1);
fill: rgba(51, 126, 169, 1);
}
.block-color-purple {
color: rgba(144, 101, 176, 1);
fill: rgba(144, 101, 176, 1);
}
.block-color-pink {
color: rgba(193, 76, 138, 1);
fill: rgba(193, 76, 138, 1);
}
.block-color-red {
color: rgba(212, 76, 71, 1);
fill: rgba(212, 76, 71, 1);
}
.block-color-gray_background {
background: rgba(241, 241, 239, 1);
}
.block-color-brown_background {
background: rgba(244, 238, 238, 1);
}
.block-color-orange_background {
background: rgba(251, 236, 221, 1);
}
.block-color-yellow_background {
background: rgba(251, 243, 219, 1);
}
.block-color-teal_background {
background: rgba(237, 243, 236, 1);
}
.block-color-blue_background {
background: rgba(231, 243, 248, 1);
}
.block-color-purple_background {
background: rgba(244, 240, 247, 0.8);
}
.block-color-pink_background {
background: rgba(249, 238, 243, 0.8);
}
.block-color-red_background {
background: rgba(253, 235, 236, 1);
}
.select-value-color-interactiveBlue { background-color: rgba(35, 131, 226, .07); }
.select-value-color-pink { background-color: rgba(245, 224, 233, 1); }
.select-value-color-purple { background-color: rgba(232, 222, 238, 1); }
.select-value-color-green { background-color: rgba(219, 237, 219, 1); }
.select-value-color-gray { background-color: rgba(227, 226, 224, 1); }
.select-value-color-translucentGray { background-color: rgba(255, 255, 255, 0.0375); }
.select-value-color-orange { background-color: rgba(250, 222, 201, 1); }
.select-value-color-brown { background-color: rgba(238, 224, 218, 1); }
.select-value-color-red { background-color: rgba(255, 226, 221, 1); }
.select-value-color-yellow { background-color: rgba(253, 236, 200, 1); }
.select-value-color-blue { background-color: rgba(211, 229, 239, 1); }
.select-value-color-pageGlass { background-color: undefined; }
.select-value-color-washGlass { background-color: undefined; }
.checkbox {
display: inline-flex;
vertical-align: text-bottom;
width: 16;
height: 16;
background-size: 16px;
margin-left: 2px;
margin-right: 5px;
}
.checkbox-on {
background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%3Crect%20width%3D%2216%22%20height%3D%2216%22%20fill%3D%22%2358A9D7%22%2F%3E%0A%3Cpath%20d%3D%22M6.71429%2012.2852L14%204.9995L12.7143%203.71436L6.71429%209.71378L3.28571%206.2831L2%207.57092L6.71429%2012.2852Z%22%20fill%3D%22white%22%2F%3E%0A%3C%2Fsvg%3E");
}
.checkbox-off {
background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%3Crect%20x%3D%220.75%22%20y%3D%220.75%22%20width%3D%2214.5%22%20height%3D%2214.5%22%20fill%3D%22white%22%20stroke%3D%22%2336352F%22%20stroke-width%3D%221.5%22%2F%3E%0A%3C%2Fsvg%3E");
}
</style></head><body><article id="d2111680-2f7b-4b25-ac84-b8b557b4695d" class="page serif"><header><img class="page-cover-image" src="https://www.notion.so/images/page-cover/met_winslow_homer_maine_coast.jpg" style="object-position:center 60%"/><div class="page-header-icon page-header-icon-with-cover"><img class="icon" src="Typescript%20d21116802f7b4b25ac84b8b557b4695d/typescript.png"/></div><h1 class="page-title">Typescript</h1><p class="page-description"></p></header><div class="page-body"><h2 id="8b4d2e56-7286-4fcb-90e4-dbe2b84b5bf3" class="">Typescript Nedir ?</h2><ul id="5792af2b-4a24-473a-a64d-539d7d649c46" class="bulleted-list"><li style="list-style-type:disc">TypeScript, JavaScript'in üst kümesidir. JavaScript'in sıkıntılı yanlarını önlemek için geliştirilmiştir. </li></ul><ul id="683a1c9b-1f1c-431a-b947-71b17333f80d" class="bulleted-list"><li style="list-style-type:disc">Typescript, Javascript'in üst kümesidir. <em>(super set) </em><strong>Super Set:</strong> Programlamada "super set", bir veri tipinin veya bir sınıfın başka bir veri tipinin veya sınıfın tüm özelliklerini içerdiği anlamında kullanılır.</li></ul><ul id="e8c1f1f6-09aa-441e-82e4-5aa3c9681a46" class="bulleted-list"><li style="list-style-type:disc">JavaScript yorumlamalıdır ve derleme aşaması yoktur. Bu nedenle, hata tespiti yapılamaz ve hata varsa tüm kodun gözden geçirilmesi gerekir. TypeScript dönüştürücüsü, derleme (compile-time) aşamasında hata denetimi yapar ve bu soruna çözüm getirir. Javascript çalıştırma aşamasında (run-time) hataları gösterir.</li></ul><ul id="9e1bb0c2-78c8-485d-8393-e80e730617ea" class="bulleted-list"><li style="list-style-type:disc"> Typescript’in asıl çıkma amacı aslında Javascript’in sıkıntılı yanlarından bizi kurtarak büyük ölçekli uygulamalar geliştirmemizi sağlamaktır.</li></ul><ul id="645f992e-eead-409b-a6b6-7610cb8aa576" class="bulleted-list"><li style="list-style-type:disc">Typescript, Javascript'in syntax'ını kullanır buna ek olarakda Tipleri destekler.</li></ul><ul id="6d327e7f-d09a-4eb3-8a75-adc15b689582" class="bulleted-list"><li style="list-style-type:disc">TypeScript JavaScript'e gelecek olan yeni özellikleri şimdiden destekler. Bu da yeni özelliklerin tarayıcılar (ya da diğer ortamlar) tarafından tamamen desteklenmese bile kullanabileceğiniz anlamına gelir.</li></ul><figcaption>Typescript browser ‘larda çalışmaz, Typescript ile yazılan kod Typescript Compiler ile javascript diline çevrilir (compiler) ve çalıştırılır.</figcaption></figure><h2 id="3072c61a-29da-4977-bdf3-12ecc48bf683" class="">TypeScript ve JavaScript Arasında Farklar Nelerdir?</h2><ul id="09786c56-357c-48fe-9e41-2c7d13576f82" class="bulleted-list"><li style="list-style-type:disc">JavaScript, etkileşimli web sayfaları oluşturmanıza yardımcı olan bir betik dilidir, Typescript ise JavaScript’in bir üst kümesidir.</li></ul><ul id="48bb203e-54f7-4ecb-99d0-8aea2794f306" class="bulleted-list"><li style="list-style-type:disc">TypeScript, nesne yönelimli bir programlama dilidir, JavaScript ise betik dildir.</li></ul><ul id="877d28d0-a27d-4bbc-89dd-e2b45f951f84" class="bulleted-list"><li style="list-style-type:disc">TypeScript, statik veri tipine sahip bir programlama dilidir, JavaScript ise dinamik veri tipine sahiptir. </li></ul><h2 id="554247c1-4592-411d-86da-ed284de56143" class="">Typescript ne zaman tercih edilmeli ?</h2><ol type="1" id="43766cda-31ab-49b3-8946-e8828aecc7cd" class="numbered-list" start="1"><li><strong>Büyük ve karmaşık projeler:</strong> Özellikle büyük ve karmaşık projelerde, JavaScript ile yazılan kodun yönetimi zorlaşabilir. TypeScript'in statik tür sistemine sahip olması, hataların daha erken keşfedilmesine ve daha sağlam bir kod tabanı oluşturulmasına yardımcı olabilir.</li></ol><ol type="1" id="e5875655-2c50-4d76-b0d1-7c3ee106823f" class="numbered-list" start="2"><li><strong>Ekibin büyüklüğü:</strong> Büyük ekiplerle çalışırken, herkesin yazdığı kodu anlamak ve değiştirmek zor olabilir. TypeScript, kod tabanını belgeleme ve daha anlaşılır hale getirme konusunda yardımcı olabilir.</li></ol><ol type="1" id="f45f862f-d8e3-40ab-85da-f4a2419ca882" class="numbered-list" start="3"><li><strong>Uzun ömürlü projeler:</strong> Bir projenin uzun ömürlü olması durumunda, projenin zaman içindeki değişikliklerini takip etmek ve güncellemek önemli olabilir. TypeScript, büyük bir proje üzerinde yapılan değişikliklerin sonuçlarını daha iyi anlayabilmeyi sağlar.</li></ol><ol type="1" id="bcdf4b73-40ab-41f6-ba11-a35e875f1fc0" class="numbered-list" start="4"><li><strong>Daha fazla güvenlik ihtiyacı:</strong> Özellikle güvenlik açısından hassas uygulamalar veya kritik işlevlere sahip projelerde, TypeScript'in statik tür sistemi, hataların erken aşamalarda tespit edilmesine yardımcı olabilir.</li></ol><ol type="1" id="6b5d509d-07b1-4389-a445-924ecb3dad4c" class="numbered-list" start="5"><li><strong>Kütüphaneler ve framework'ler:</strong> TypeScript, bazı popüler kütüphaneler ve framework'ler tarafından doğrudan desteklenmektedir. Örneğin, Angular framework'ü TypeScript üzerine kuruludur ve React ve Vue.js gibi diğer kütüphaneler de TypeScript'i destekler.</li></ol><ol type="1" id="cd5ca467-994d-439c-b9e4-57472c2306f5" class="numbered-list" start="6"><li><strong>Entegrasyon kolaylığı:</strong> TypeScript, JavaScript kodlarına kolayca entegre edilebilir. Mevcut bir JavaScript projesinin TypeScript'e geçirilmesi zaman alsa da, TypeScript dosyalarını yavaş yavaş eklemek ve daha sonra projeyi tamamen TypeScript'e dönüştürmek mümkündür.</li></ol><details open=""><summary style="font-weight:600;font-size:1.5em;line-height:1.3;margin:0">tsconfig.json</summary><div class="indented"><p id="c18eddd1-9ac1-4244-a3ce-7062b2079f75" class=""><mark class="highlight-yellow_background"><code><strong>target</strong></code></mark>: Hedef ECMAScript sürümünü belirtir (örn. <code><strong>"es5"</strong></code>, <code><strong>"es6"</strong></code>, <code><strong>"es2017"</strong></code>, vb.). Derlenen çıktı, belirtilen sürümdeki JavaScript'e uygun olacaktır.</p><pre id="15703778-7dda-475e-b67d-8862f1a6ea4e" class="code"><code>"target": "ES6",</code></pre><p id="8664eeea-2a43-49e9-a6d8-0114af71df6d" class=""><mark class="highlight-yellow_background"><code><strong>module</strong></code></mark>: Hangi modül sisteminin kullanılacağını belirtir (örn. <code>"CommonJS"</code>, <code><strong>"AMD"</strong></code>, <code><strong>"ES6"</strong></code>, vb.).</p><pre id="811dd828-801b-4bbd-bc03-edbcaaa1e1db" class="code"><code>"module": "ES6",</code></pre><p id="685de6ef-d6e7-40ac-8793-59092cbe016d" class=""><mark class="highlight-yellow_background"><code><strong>lib</strong></code></mark>: Bu ayar, TypeScript derleyicisinin kullanılabilir kütüphane tanımlarını belirler.
Örneğin, <code><strong>"es6"</strong></code>, <code><strong>"dom"</strong></code>, <code><strong>"esnext.asynciterable"</strong></code> gibi değerlerle kütüphaneleri ekleyebilirsiniz</p><pre id="7c135d2f-4d59-494d-bbce-971e230bbaca" class="code"><code>"lib": ["ES6", "DOM", "DOM.Iterable"],</code></pre><p id="987cc2f1-187f-4b85-b6a8-dc1bf9bce638" class=""><mark class="highlight-yellow_background"><code><strong>exclude</strong></code></mark>: Derleme işleminde hariç tutulacak dosya veya dizinleri belirtir. Kod yazarken hata göstermeye devam eder fakat npm run build (derleme) yaparken hataları görmezden gelir, diğer türlü build alırken hata varsa build işlemi gerçekleşmez.</p><pre id="d5e9e1e8-15d2-48c3-9ef6-e1dfb30e15f1" class="code"><code>"exclude": ["src/kira.tsx"],</code></pre><p id="b099e1e5-d44d-4f3d-8c27-d8d56fdde2d4" class=""><mark class="highlight-yellow_background"><code><strong>include</strong></code></mark>: Derleme işleminde dahil edilecek dosya veya dizinleri belirtir. Genellikle <code><strong>*/*</strong></code> kullanarak tüm dosyaları ve alt dizinleri dahil edebilirsiniz.</p><pre id="f675aaf1-b776-4257-ae5d-3e63144c661b" class="code"><code>"include": ["src"],</code></pre><p id="1cfb61eb-4b41-43df-beb9-2df2d8dbb26d" class=""><mark class="highlight-yellow_background"><code><strong>skipLibCheck</strong></code></mark><strong> </strong>Bu ayar, kütüphane tanımlarını (<code><strong>.d.ts</strong></code> dosyalarını) denetleyip denetlemeyeceğini belirler. Büyük ve karmaşık bir proje çalışıyorsanız veya dışarıdan alınan kütüphaneleri kullanıyorsanız, bu denetimlerin derleme sürecini yavaşlatabileceği ve gereksiz hataların oluşabileceği durumlar olabilir.</p><pre id="76b9798a-e92e-4368-ad35-bbe4ddef8de7" class="code"><code>"skipLibCheck": true</code></pre><p id="a74cc497-101e-4094-bc0a-307b210b7c80" class=""><mark class="highlight-yellow_background"><code><strong>strict</strong></code></mark> : Katı tür denetimlerini etkinleştirir. Kodun hatasız ve güvenli olmasını sağlar.</p><pre id="c1131dbd-84c5-4d97-a23a-03f970320561" class="code"><code>"strict": true,</code></pre><p id="58c82d86-3f01-4066-8ed8-2e4d22e347c3" class=""><mark class="highlight-yellow_background"><code><strong>noImplicitAny</strong></code></mark> : Değişken veya fonksiyon dönüş değeri türleri belirtilmediğinde (<code><strong>any</strong></code> olarak varsayıldığında) hata oluşturur (<code><strong>true</strong></code>)</p><pre id="2795a72f-918f-4a99-8906-d2e9459550b8" class="code"><code>"noImplicitAny": true</code></pre><p id="5d87a0fb-d36b-4e54-96a0-6637e30a4614" class=""><code><mark class="highlight-yellow_background"><strong>strictNullChecks</strong></mark></code> : Sadece null ve undefied atamalarını uygun değişkenlere atayabilmeye izin verir. Tip uyumsuzluğundan kaynaklanabilecek olası hataları önlemek içindir. Örneğin, bir değişkenin türü <code><strong>number</strong></code> olabilirken, bu değişkene <code><strong>null</strong></code> veya <code><strong>undefined</strong></code> atamakta bir sorun olmaz.</p><pre id="2dc9a851-8c37-44dc-bd5e-4132cf095806" class="code"><code>"strictNullChecks": true</code></pre><p id="92d3fe7e-f7f1-4633-9e84-4c95b9ed8489" class=""><mark class="highlight-yellow_background"><code><strong>sourceMap</strong></code></mark>: Kaynak haritalarının oluşturulmasını (<code><strong>true</strong></code>) veya oluşturulmamasını (<code><strong>false</strong></code>) belirtir. Kaynak haritaları hata ayıklamayı kolaylaştırır.</p><pre id="44094344-72ca-430a-bc59-9b2c6508b9e0" class="code"><code>"sourceMap" : true</code></pre><p id="b3d462f5-6a97-4147-9114-bb35971e9f8f" class=""><mark class="highlight-yellow_background"><code><strong>outDir</strong></code></mark>: Derlenmiş çıktının nereye konulacağını belirtir.</p><pre id="2727981f-de5e-4f6c-ae39-8f1f12b108f3" class="code"><code>"outDir": "./dist"</code></pre><p id="25f7258b-5b4a-4ae6-9459-91014a139d85" class=""><mark class="highlight-yellow_background"><code><strong>extends</strong></code></mark> Yapılandırma dosyalarını bölümlere ayırabilir ve birbirinden miras (extends) almasını sağlayabilirsiniz.</p><p id="5464e7e3-eb17-4cae-890e-73ff83c99629" class="">Temel yapılandırma dosyası: <code><strong>tsconfig.base.json</strong></code></p><pre id="3cf739ac-d10d-4148-90b7-22a8ed68e283" class="code code-wrap"><code>
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true}
}</code></pre><p id="0dd1699c-1a58-496b-86fa-a1edf9914c97" class="">Diğer dosya: <code><strong>tsconfig.app.json</strong></code></p><pre id="0bff618d-926f-45fa-8b9c-7ad2e9d29d65" class="code code-wrap"><code>
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src"]
}
</code></pre><p id="7986f1bb-113c-4374-a044-8102c2c95194" class=""><code><strong><mark class="highlight-yellow_background">files</mark></strong></code> : Derleme işlemi sırasında dahil edilecek dosyaları belirler. Bu, projenizin yalnızca belirli dosyaların derlenmesini istediğiniz durumlarda kullanışlı olabilir.</p><pre id="a1f0cddc-cc30-4073-8f06-7a5766d071cc" class="code"><code>"files": [
"app.tsx",
"helpers/utility.tsx"
]</code></pre><p id="c3b75f91-5d85-4ca4-ab58-01e7a90d26c5" class=""><mark class="highlight-yellow_background"><code><strong>compilerOptions.paths </strong></code></mark>: Modül yollarını kısaltmak ve modül tanımlarının yerini belirli kısaltmalara göre eşleştirmek için kullanılır. baseUrl ile birlikte kullanılır.</p><pre id="1a11276f-c66a-47b2-bb3c-fbff4d22597f" class="code"><code>"compilerOptions": {
"target": "es6",
"module": "commonjs",
"baseUrl": "./src",
"paths": {
"@utils/*": ["utils/*"],
"@models/*": ["app/models/*"]
}</code></pre><pre id="9af2e42c-3420-4e7f-be66-5ac00df50226" class="code"><code>import { add } from "@utils/math";
import { User } from "@models/user";</code></pre><p id="0e24a976-37ce-4d14-920d-886c6072fd28" class=""><mark class="highlight-yellow_background"><code><strong>allowJs</strong></code></mark> :TypeScript derleyicisine JavaScript dosyalarını (<code><strong>*.js</strong></code> uzantılı dosyaları) derleme işlemine dahil etme izni verir. Default false ‘dir. Özellikle mevcut bir projeyi TypeScript'e geçirirken veya TypeScript ve JavaScript dosyalarını aynı proje içinde kullanırken faydalı olabilir.</p><pre id="da2a8408-e696-4608-a542-bf5d86b865bb" class="code"><code>"allowJs": false //dahil etmez /dafault)</code></pre><p id="857c6a38-d24f-44b5-b198-1b16d75a4c7a" class=""><mark class="highlight-yellow_background"><code><strong>checkJs</strong></code></mark> : JavaScript dosyalarında (<code><strong>.js</strong></code> uzantılı dosyalarında) tür denetimi yapma izni verir. Derleme işlemi sırasında tür denetimini kontrol eder. allowJs ise dosyayı derleme işlemini dahil edip etmemeyi sağlar.</p><pre id="f50c8902-f0ab-4a3e-813c-cc61ebdd92fe" class="code"><code>"checkJs": false //kontrol etmez (default)</code></pre><p id="9985ef81-bbd3-42d4-9f17-9e6e13b886ea" class=""><mark class="highlight-yellow_background"><code><strong>noEmit</strong></code></mark> : Derleme sırasında çıktı dosyalarının üretilip üretilmeyeceğini kontrol eder. Yalnızca tür denetimi yapmak ve derleme sürecinde yalnızca hataları kontrol etmek istediğinizde ve çıktı dosyasına (yani derlenen .js dosyasına) ihtiyaç duymadığınızda kullanışlıdır."noEmit": true</p><pre id="70763fba-bbec-49d3-9d1f-804827640ae7" class="code"><code>"noEmit": false //çıktı üretir (default)</code></pre><p id="054e5106-af8d-4fde-aa04-83f212cfa880" class=""><mark class="highlight-yellow_background"><code><strong>noUnusedLocals</strong></code></mark><strong> :</strong> Kullanılmayan değişkenleri kontrol eder ve hata döndürür.</p><pre id="7cb80460-4dee-4d39-9b9e-f0ff44f8ec6b" class="code"><code>noUnusedLocals : true //control et ve uyar</code></pre><p id="8a4349cf-1bd7-4235-b905-1d59d71703fc" class=""><mark class="highlight-yellow_background"><code><strong>noUnusedParameters</strong></code></mark><strong> :</strong> Kullanılmayan fonksiyona gönderilen parametreleri kontrol eder.</p><pre id="a040c7d4-6bfc-4175-876d-18446e4b9574" class="code"><code>noUnusedParameters : true //control et ve uyar</code></pre><p id="8d3243da-0e66-4e7c-9d7b-9878287a308e" class=""><mark class="highlight-yellow_background"><strong><code>allowImportingTsExtensions</code></strong></mark><strong> :</strong> Diğer .ts veya .tsx dosyalarını import edebilme izni verir. Genelde componentleri birbirleri arasında sürekli import ettiğimiz için bu ayarı hep true tutmalıyız. Default false.</p><pre id="ab07a82d-0441-4175-a29b-7d24ac2a232e" class="code"><code>allowImportingTsExtensions : true //dosyaları import edebilirsin.</code></pre><p id="1f43799e-7d9d-4f09-ae76-c6442e36bff8" class=""><mark class="highlight-yellow_background"><code><strong>resolveJsonModule</strong></code></mark><strong> :</strong> Diğer .json dosyalarını import edebilme izni verir. Default false.</p><pre id="d2fe74c2-9730-495b-a30f-f5ffa5efa606" class="code"><code>resolveJsonModule : true //dosyaları import edebilirsin.</code></pre><p id="3c8c45cb-fbd4-4f36-8c4b-ce093dd244a6" class=""><mark class="highlight-yellow_background"><code><strong>isolatedModules</strong></code></mark><strong> :</strong> Tüm .ts veya .tsx dosyaları nasıl parça parça ise o şekilde derlenip çıktı olarak .js dosyalarına dönüştürülür. Default false ‘dir yani componentlerinizi ayırsanız bile tek bir dosyada derler ve çıkarır.</p><pre id="48dbc4cc-d7e8-496b-acd6-7e13118e2f8c" class="code"><code>isolatedModules : true //her component kendi adında dosya ile çıkarılır.</code></pre><p id="a38614e7-3ae2-4009-834a-e02f8b3bffdc" class="">
</p></div></details><h3 id="4685bf37-23bc-45e7-9874-1c0d55cf9fd4" class="">Typescript klasör yapısı</h3><p id="3b9aca8e-e040-4175-8a34-d351597bf889" class="">Projelerde tip dosyaları oluştururken genellikle dosya ismine “d” ifadesi koyulur. Kalıplaşmış kullanımdır.</p><pre id="4f9f3bb6-8f53-4fd0-990e-ff091e5fd33d" class="code"><code>index.ts //Dosyaları dışarıya çıkarma ve erişim işlemleri.
Person.tsx //Componentin içeriği
person.d.ts //declaration tip dosyası (içerisinde type ve interface kavramları bulunur)
constants.ts //Asla değişmeyecek bazı belirlenmiş değerlerin olduğunu dosya.</code></pre><h3 id="3a8b1776-480b-461b-be63-69c001dfee6a" class="">Object</h3><pre id="a95595b8-a836-4e00-b613-eec0d7dbb966" class="code"><code>const person: {
ad: string,
yas: number,
sehir: any,
tarih: Date,
check: boolean,
dersNotlari: {},
func: Function
} = {
ad: "Kaira",
yas: 20,
sehir: "Ankara",
tarih: new Date(),
check: true,
dersNotlari: {matematik: 25, turkce: 74},
func: () => {
return 5
}
}</code></pre><h3 id="b05010ab-e1fb-4c13-94e9-c492b236fed9" class="">Array[]</h3><pre id="3a9bb4cd-14b2-4f2b-8c90-b704b086c21b" class="code"><code>//Sadece string tipinde değer alabilir
const person: string[] = ["Hellow", "World"];
//Sadece string veya number tipinde değer alabilir.
const person: (string | number)[] = ["Hellow", "World",25];</code></pre><h3 id="6e50dd4d-b233-401f-af4a-616863280fa2" class="">type</h3><pre id="666f925b-ec52-4a4b-92b9-8f56d30637a3" class="code"><code>type persontype = string | number[];
const person: persontype = "kaira"
const person: persontype = [12,44,28]</code></pre><pre id="9c839bcf-4b82-4fdf-8927-3554165b6ef4" class="code"><code>type persontype = any[];
const person: persontype = ["john", {name: "kaira"}, [44, 44], () => console.log("okey")]</code></pre><pre id="b362baab-b75d-4a68-bea2-5a707226ca80" class="code"><code>type Cat = number;
type Dog = Cat;
let person: Dog = 2;</code></pre><pre id="26dde1ff-37b2-42c6-80e4-3262346980ae" class="code"><code>type Dog = string;
type Cat = number;
let person: Dog | Cat = 2;</code></pre><pre id="8b03c0b8-4129-4b35-becc-695b93f9f187" class="code"><code>type Dog = string;
type Cat = number;
type DogCat = Dog | Cat
let person: DogCat = 2;
let person: DogCat = 'John';
</code></pre><pre id="de18a55e-b0bd-4c5f-87ab-e5049f0f587c" class="code"><code>type IPerson = () => number
const Person: IPerson = () => {
return 25
}
type IPerson = (isim: string, yas: number) => number
const Person: IPerson = (isim,yas) => {
return yas;
}</code></pre><h3 id="58f95614-0fb6-4a80-aad3-f30da6f9a989" class="">interface</h3><pre id="3c8e5929-abc5-4824-9885-c2e96c63ac0c" class="code"><code>interface PersonTypes {
ad: string,
yas: number,
sehir: any,
tarih: Date,
check: boolean,
func: Function,
dersNotlari: {}
}
const person: PersonTypes = {
ad: "Kaira",
yas: 20,
sehir: "Ankara",
tarih: new Date(),
check: true,
func: () => {
return 5
},
dersNotlari: {matematik: 25, turkce: 74}
}</code></pre><pre id="411f77e6-5980-423c-92e9-491224651947" class="code"><code>interface Dog {
name: string
age: number
}
interface Cat {
name: string,
gender: 'male' | 'female'
}
// & operatöründe 2 interface 'de olan değerlerin tümünü kullanmak zorundayız
type DogCat = Dog & Cat;
let person: DogCat = {name: 'Karabaş', age: 4, gender: 'male'};</code></pre><pre id="f393f47c-abee-44a8-9453-82382956a71f" class="code"><code>// person fonksiyonun geri dönüş değeri IPerson interfacenin isim adlı değeri
// ile aynı yani string döndürecek.
interface IPerson {
isim: string;
yas: number;
}
const person = (): IPerson['isim'] => {
return 'Kaira
}</code></pre><pre id="24ad4c14-a979-473e-9a70-d83cce991e3c" class="code"><code>// Array 'lar için index değerlerini number ve key değerlerini string belirledik.
// indexler person[0] , person[1] şeklinde düşünülebilir. artık bu array içerisine
// sadece string değerler kabul edecektir.
interface IPerson {
[index: number]: string
}
const person: IPerson = ['Kaira', 'katarina']</code></pre><pre id="433e8044-d53b-49a9-a40b-e32e8eb10e85" class="code"><code>interface IPerson {
(): void
}
const person: IPerson = () => {
console.log('Hellow');
}
interface IPerson {
(a: number, b: number): number
}
const person: IPerson = (a,b) => {
return a + b
}
</code></pre><pre id="092d0bd8-b5d9-4bde-950b-caa8edb9dda8" class="code"><code>//Extends
interface IUser{
no: number,
isim: string
}
interface IPerson extends IUser{
yas: number,
sehir: string
}
const person1: IPerson = {
no: 1,
isim: 'Kaira',
yas: 19,
sehir: 'London'
}</code></pre><h3 id="09ddb450-bfa4-45eb-a6db-56d2dcb67ade" class="">as</h3><pre id="7cb5a778-45cd-4420-8fe7-3e145d277aef" class="code"><code>const person: string = "Kaira";
const person = "Kaira" as string;</code></pre><p id="f850e913-0006-4bdd-891d-193e60974274" class="">Tür güvenliğini korumak için tür dönüşümlerini ve <code><strong>as</strong></code> anahtar kelimesini olabildiğince az kullanmanızı, mümkünse tür çıkarımına dayalı bir yaklaşım benimsenmeli. (type, interface)</p><pre id="23ded26b-c7fd-4af4-ba30-a49384999f75" class="code"><code>type persontype = number[];
const person = [12, 24, "john"] as persontype // hatalı olduğu halde hata vermez.
const person: persontype = [12, 24, "john"]; // hatalı olduğunu belirtir, sağlıklıdır.</code></pre><h3 id="09b98446-0d78-49f1-accf-7862ecc74114" class="">Sabit değerler</h3><pre id="1132726c-f71b-4706-b631-74fa3d42aece" class="code"><code>const sayilar: 25 | 12 | "John" = 12;
type persontype = 25 | 12 | "John"
const person: persontype = 12;</code></pre><pre id="2af6942f-4f4d-4dbf-a54f-c2bc569c0e20" class="code"><code>type PersonType = [string, string, number];
const person: PersonType = ["Kaira", "Katarina", 24]</code></pre><pre id="282278e7-4a5a-45af-8017-6a0e98019cde" class="code"><code>type PersonType = [string, 25 | 24 | string[], number];
const person: PersonType = ["Kaira", 12, 24] // error
const person: PersonType = ["Kaira", 24, 24] // true
const person: PersonType = ["Kaira", ["tt", "bb"], 24] // true
const person: PersonType = ["Kaira", ["tt", "bb", 12], 24] // true</code></pre><h3 id="3fc5392d-b8cb-4d9e-a2c9-c6adeb26234f" class="">Fonksiyonlar</h3><pre id="4aa96580-d5de-4975-863a-63b22fe86053" class="code"><code>// Geriye bir değer döndürmüyor ise tipi void
const func = () => { }
// Aynı şekilde void tipi
const func = () => { console.log("Hello"); }
// Bu fonksiyon geriye bir değer döndürdüğü için tipi otomatik number olur.
const func = () => { return 25; }</code></pre><pre id="5181e954-47fb-4c76-b1cf-0dae998c17d4" class="code"><code>// geriye bir değer döndürmeyeceğini belirtiyorum
function func(): void {
console.log("Hello")
}
const func = () : void => {
console.log("Hello")
}</code></pre><pre id="193e13a4-3f32-4b1f-8bf8-4ce4935a2eae" class="code"><code>const func = (): number => {
return 25
}
// geriye number döndürür veya hiçbir değer döndürmeyebilir
const func = (): void | number => {
return 25
}
const func = ():(string | number)[] => {
return [25,12,44,"John"]
}
function func(): [string, string, number] {
return ["Kaira", "Katarina", 25];
}</code></pre><pre id="cf2a217d-711f-418e-8d4e-70e4f2d66408" class="code"><code>function func(): number {
return 25;
}
let test: string = func() // error string bir değere number değer atayamazsın.</code></pre><h3 id="4a9ee27c-3d7e-417f-9c61-656afa0527ad" class="">Parametreler</h3><pre id="dfaa460c-9d23-4ad6-b818-f243e7a2c05a" class="code"><code>function func(text: string, repeat: number): void {
for (let i = 1; i <= repeat; i++) {
console.log(text);
}
}
func("Hello Wrold", 4);</code></pre><p id="0f986cc0-f49e-44f4-a008-688bc290f08f" class="">Aşağıdaki kodda 2 hata mevcut. İlki text parametresi aldığımız halde bunu kullanmamamız, ikinci olarak geri dönüş tipini number olarak belirttik fakat return metodu for döngüsü içerisinde yer aldığı için yani ana parantezin içerisinde return değeri olmadığı için geriye bir şey döndürmeme ihtimaline karşı typescript number tipine ek olarak undefined tipinide eklememizi istiyor.</p><pre id="505f4990-f547-4cc2-942b-d07f31cc37d2" class="code"><code>function func(text: string, repeat: number): number {
for (let i = 1; i <= repeat; i++) {
return 25; // return ifadesi döngüyü 1 kere çalıştırıp sonlandırır.
}
}
function func(text: string, repeat: number): number {
for (let i = 1; i <= repeat; i++) {
console.log(text);
}
return 25; //artık geri dönüş tipinin number olduğunu kabul eder.
}</code></pre><pre id="db0bcf3a-f471-4126-8971-f1cf018371b6" class="code"><code>//obje olarak paremetre almak
function func(parameters: { text: string, repeat: number }): number {
const {text, repeat} = parameters;
for (let i = 1; i <= repeat; i++) {
console.log(text);
}
return 25;
}</code></pre><h3 id="a16dd181-71a9-45c3-bf5a-530c5b3b0c52" class="">Opsiyonel parametreler</h3><p id="15c00b93-16ac-474c-8fcb-001a4b9b8ea4" class="">Opsiyonel parametreler, bir işlevin çağrıldığında isteğe bağlı parametreleri ifade etmek için kullanılır.</p><pre id="1cb4c504-dbab-4cba-b92c-84dca259bce7" class="code"><code> const func = (text : string, sayi?: number) => {
console.log(text)
}
func("Hellow"); //sayi opsiyonel olduğu için belirtmesek 'de hata vermez.</code></pre><h3 id="8c143917-49b3-4564-a653-92dbdd55430e" class="">Normal fonksiyon ve arrow fonksiyon tiplendirme farkı</h3><p id="629ea681-ed17-4ef7-996c-a639840cd5d2" class="">Normal fonksiyonları type ile tiplendiremeyiz çünkü type ‘da fonksiyon tipi tanımlarken arrow function tipinde tanımlıyoruz ve bunu normal fonksiyon kabul etmez. <code>=> string</code></p><pre id="952b19c2-826d-4643-9786-37e5cc22251f" class="code"><code>type IPerson = (isim: string) => string
function Person(isim): IPerson{
return isim;
}</code></pre><p id="b656f03f-5643-4247-9b5b-dd1ef0bbfd5b" class="">Bunun çok sağlıklı olmayan bir çözümü vardır, bir fonksiyon tanımlarız ve bu fonksiyon da geriye yeni bir fonksiyon döndürür, en dıştaki fonksiyon parametre almaz, geriye döndürdüğü fonksiyon parametre alır. Typescript ilgili tanımlamaları otomatik yapar. Çağırırken fonksiyonun içerisindeki fonksiyona parametre veririz. <code>FunctionName()(’parametre’)</code></p><pre id="37077b33-edc7-4405-885e-f5754ed7b579" class="code"><code>type IPerson = (isim: string) => string
function Person(): IPerson{
return function(isim){
return isim;
}
}
Person()('Kaira')</code></pre><p id="de62a80f-b897-40c1-981e-e04428b6176b" class="">Bu şekilde kullanmak zahmetli ve sağlıklı değildir bunun için <code>interface</code> çözümdür.</p><h3 id="c0018cc8-337f-45c3-ab91-19d8f014963c" class="">Partial (Obsiyonel Obje)</h3><p id="889ecd6d-b411-4946-8311-be9297fe89be" class=""><code>Partial </code>metodu tüm değerlerin obsiyonel olacağını belirtir.</p><pre id="f548e82e-e486-45d6-8e8e-7e1f96c75990" class="code"><code>// Aşağıdaki tanımlamada isim ve yas değerinin belirtilmesi zorunludur.
interface PersonTypes {
isim: string;
yas: number;
}
// Partial ile tüm değerlerin obsiyonel olabileceği yeni bir tip oluşturduk.
type OpsionelType = Partial<PersonTypes>;
const Person: OpsionelType {
isim: 'Kaira'
}</code></pre><pre id="5ee56da6-af1c-4986-bd26-f88a1ccc3a78" class="code"><code>//key lerin sonuna "?" koyarak hangilerinin obsiyonel olabileceğini belirtilebiliriz.
interface PersonTypes {
isim: string;
yas?: number;
}
const Person: PersonTypes {
isim: 'Kaira'
}</code></pre><h3 id="ad6364ac-ecdc-4d3a-aaa3-54ad01f43bed" class="">Required</h3><p id="b81ee472-3db5-4b3e-b41d-72e7af8f4195" class="">Opsiyonel olan değerlerde dahil tüm tipleri zorunlu kılar.</p><pre id="a00a0691-ed48-48b7-b3fb-e421cc1fcea1" class="code"><code>interface IPerson {
name?: string;
age?: number;
}
const person: Required<Person> {
name: 'Kaira',
age: 24
}</code></pre><h3 id="fb63278e-ba25-40b2-8d7d-691bd96daf67" class="">index signature - Objeye belirtilmemiş tip deki değerleri ekleyebilmek</h3><p id="60df35f7-009d-43cd-a738-c30bc20578ad" class="">Tip olarak tanımlanmamış değerlerin obje içerisine kabul edilebilmesi için [key: string]: <tip> şeklinde belirtilmesi gerekiyor. Aşağıda any tipinde her değeri kabul edeceğini belirttik.</p><pre id="376f0b26-20fd-4947-9d80-59d94640f32b" class="code"><code>interface PersonTypes {
isim: string;
yas: number;
[key: string]: any;
}
const Person: OpsionelType {
isim: 'Kaira'
yas: 25
sehir: "İstanbul"
ilce: "Bebek"
}</code></pre><p id="ad4c5cd7-385d-4c8c-9999-f854d4229101" class="">Ek olarak diğer tiplerde değer de kabul edebileceğini belirtebiliriz fakat <code><strong>önemli :</strong></code> any haricinde tip belirtirken kullanılan diğer tipleride belirtmek zorundayız. Aşağıda boolean bir değer alabileceğini belirttik fakat isim ve yas ‘ın tipinide yanına eklemek zorundayız.</p><pre id="25e7c133-385c-4809-9f95-d01f7ede23e8" class="code"><code>interface PersonTypes {
isim: string;
yas: number;
[key: string]: string | number | boolean;
}
const Person: OpsionelType {
isim: 'Kaira'
yas: 25
durum: true
}</code></pre><h3 id="232b8453-f017-4e3f-a81d-69a580fc7b98" class="">Record</h3><p id="e130b007-d681-46b7-8e1d-4f3969bc3725" class="">Objelerde key ve value şeklinde tip atamaları yapmamızı sağlar. <code>Record<key , value></code>
Herhangi bir özel key ve value belirtmeden sadece tip atamsı yaparak opsiyonel değerler üretebiliriz.</p><pre id="cdff1bd3-01c0-4f8f-9fcb-77509fecff94" class="code"><code>const person: Record<string,number> = {
yas: 25,
sınıf: 3
}
const person: Record<string, boolean | number> = {
yas: 25,
check: true
}
const person: Record<string, {isim: string, yas?: number, check: boolean}> = {
person1: {
isim: 'kaira',
yas: 19,
check: true
},
person2: {
isim: 'katarina',
check: false
},
}</code></pre><h3 id="8ac1f603-66e7-49a1-9e00-618580c9aad5" class="">Omit</h3><p id="5ef957d8-86b1-42e7-9c95-30fb735a59ee" class="">Belirli bir interfacede kullanmak istemediğimiz tip tanımlamalarını çıkararak geriye bir interface döndürür. <code>Omit<interfaceName, disableTypeName></code></p><pre id="18960ef1-4d0a-4356-bdeb-872466548fe0" class="code"><code>interface IPerson{
name: string;
age: number;
date: Date;
}
const person : Omit<IPerson, 'date'> = {
name: 'John',
age: 21
}</code></pre><h3 id="2f651b52-5a31-4afb-bb32-5a181c402240" class="">Pick</h3><p id="4f394479-3762-4d88-b15f-cd806fc0abf4" class="">Omit in tersi olarak başka bir interface ‘de ki seçili tip veya tiplerin kullanılmasını ister.
<code>Omit<interfaceName, enabledTypeName></code></p><pre id="bda59cfd-b8e6-4d5f-a12c-4db410d33a38" class="code"><code>interface IPerson {
name: string;
age: number;
date: Date;
}