-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathtypescript.json
More file actions
304 lines (304 loc) · 17.8 KB
/
Copy pathtypescript.json
File metadata and controls
304 lines (304 loc) · 17.8 KB
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
{
"id": "typescript",
"title": "টাইপস্ক্রিপ্ট",
"slug": "typescript",
"description": "টাইপস্ক্রিপ্ট জাভাস্ক্রিপ্ট ল্যাংগুয়েজের একটি সুপারসেট। এটির উদ্দেশ্য হলো জাভাস্ক্রিপ্টকে স্ট্রংলি টাইপড ল্যাংগুয়েজের একটা ফ্লেভার দেওয়া যাতে আমাদের কোডের ইরর সহজে ধরা পড়ে এবং এপ্লিকেশনের অনেক অনাকাঙ্ক্ষিত আচরণ থেকে আমরা রক্ষা পাই। টাইপস্ক্রিপ্ট জাভাস্ক্রিপ্টের মত ব্রাউজারে লেখা যায় না।",
"colorPref": "#2E86C1",
"contents": [{
"title": "ইন্সটলেশন ও কনফিগারেশন",
"items": [{
"definition": "গ্লোবালি টাইপস্ক্রিপ্ট ইন্সটল করা (yarn এর সাহার্যে)",
"code": "yarn global add typescript"
},
{
"definition": "গ্লোবালি টাইপস্ক্রিপ্ট ইন্সটল করা (npm এর সাহার্যে)",
"code": "npm install typescript -g"
},
{
"definition": "লোকাল প্রজেক্টে টাইপস্ক্রিপ্ট ইন্সটল করা (yarn এর সাহার্যে)",
"code": "yarn add typescript"
},
{
"definition": "লোকাল প্রজেক্টে টাইপস্ক্রিপ্ট ইন্সটল করা (npm এর সাহার্যে)",
"code": "npm install typescript"
},
{
"definition": "টাইপস্ক্রিপ্ট প্রজেক্টে ইনিশিয়ালাইজ করা",
"code": "tsc --init"
},
{
"definition": "একটি নির্দিষ্ট ফাইলকে কম্পাইল করা",
"code": "tsc app.ts"
},
{
"definition": "একটি নির্দিষ্ট ফাইলকে ওয়াচমোডে কম্পাইল করা",
"code": "tsc app.ts -w"
},
{
"definition": "সব টাইপস্ক্রিপ্ট ফাইলকে কম্পাইল করা",
"code": "tsc"
},
{
"definition": "সব টাইপস্ক্রিপ্ট ফাইলকে ওয়াচমোডে কম্পাইল করা",
"code": "tsc -w"
},
{
"definition": "কোন ফাইলকে কম্পাইল করতে না চাইলে tsconfig.json ফাইলে গিয়ে শেষ ব্র্যাকেটের আগে এভাবে কোড লিখতে হবে",
"code": "\"exclude\": [\n\t\"example.ts\",\n\t\"example2.ts\",\n\t\"*.dev.ts\", //.dev.ts দিয়ে শেষ হওয়া ফাইলগুলো বাদ \n\t\"**/*.dev.ts\" //সব ফোল্ডারে .dev.ts দিয়ে শেষ হওয়া ফাইলগুলো বাদ\n]"
},
{
"definition": "কোন ফাইলকে কম্পাইল প্রোসেসে এড করতে চাইলে tsconfig.json ফাইলে গিয়ে শেষ ব্র্যাকেটের আগে এভাবে কোড লিখতে হবে",
"code": "\"include\": [\n\t\"app.ts\"\n]"
}
]
},
{
"title": "ডেটাটাইপ",
"items": [{
"definition": "বেসিক ডেটাটাইপগুলো",
"code": "Any, number, string, boolean, object, Array, Tuple, Enum, undefined, null, void, never, unknown"
},
{
"definition": "ইউনিয়ন ডেটাটাইপ",
"code": "const userId: number | string"
},
{
"definition": "ইন্টারসেকশন ডেটাটাইপ",
"code": "let myIntersectionType: Foo & Bar;"
},
{
"definition": "লিটারেল ডেটাটাইপ (স্ট্রিং)",
"code": "let direction: 'left' | 'right'"
},
{
"definition": "লিটারেল ডেটাটাইপ (নাম্বার)",
"code": "let roll: 1 | 2 | 3 | 4 | 5"
},
{
"definition": "লিটারেল ডেটাটাইপ (বুলিয়ান)",
"code": "let isOnline: true | false"
}
]
},
{
"title": "ভ্যারিয়েবল",
"items": [{
"definition": "ভ্যারিয়েবল ডিক্লারেশন",
"code": "let age: number"
},
{
"definition": "ভ্যারিয়েবল ডিক্লারেশনের সময় ভ্যালু এসাইন করা",
"code": "let age: number = 20"
},
{
"definition": "টাইপের এলিয়াস/উপনাম",
"code": "type Direction: 'left' | 'right';\nlet direction: Direction;"
},
{
"definition": "টাইপের এসারশন",
"code": "let someValue: any = 'this is a string';\nlet strLength: number = (someValue as string).length;\nconst myCanvas = document.getElementById('main_canvas') as HTMLCanvasElement;"
}
]
},
{
"title": "অ্যারে ও টাপল",
"items": [{
"definition": "অ্যারে ডিক্লারেশন",
"code": "let ages: number[]"
},
{
"definition": "অ্যারেতে ভ্যালু এসাইন করা",
"code": "ages = [12, 5];"
},
{
"definition": "ইউনিয়ন টাইপ অ্যারে ডিক্লারেশন",
"code": "let x: (number | boolean | string)[];"
},
{
"definition": "ইউনিয়ন টাইপ অ্যারেতে ভ্যালু এসাইন করা",
"code": "x = [23, true, 'AnyString'];"
},
{
"definition": "অ্যারের কোন পজিশনের ভ্যালু এক্সেস করা",
"code": "let secondAge = ages[1]"
},
{
"definition": "টাপল ডিক্লারেশন",
"code": "let tp: [number, string]"
},
{
"definition": "টাপলে ভ্যালু এসাইন করা",
"code": "tp = [10, 'player']"
},
{
"definition": "কন্ডিশনাল টাপল ডিক্লারেশন",
"code": "let tp: [number, string?]"
},
{
"definition": "কন্ডিশনাল টাপলে ভ্যালু এসাইন করা",
"code": "tp = [10]"
}
]
},
{
"title": "ফাংশন",
"items": [{
"definition": "কন্সট্রাক্টর",
"code": "new () => ConstructedType;"
},
{
"definition": "ফাংশন প্যারামিটার ও রিটার্ন টাইপ",
"code": "function add (n1: number, n2: number) => number; \n\n\t //or \n\nfunction add (n1: number, n2: number): number;"
},
{
"definition": "এরো ফাংশন",
"code": "let greeting = (name: string): string => {\n\treturn \"Hello \" + name;\n}\n\nlet greetUser = greeting(\"Shadab\")\nconsole.log(greetUser);"
},
{
"definition": "অপশনাল প্যারামিটার",
"code": "(arg1: Type, optional?: Type) => ReturnType"
},
{
"definition": "ডিফল্ট প্যারামিটার",
"code": "function fn(arg1 = 'default'): ReturnType {}"
},
{
"definition": "রেস্ট প্যারামিটার",
"code": "(arg1: Type, ...allOtherArgs: Type[]) => ReturnType"
},
{
"definition": "ওভারলোড",
"code": "function conv(a: string): number;\nfunction conv(a: number): string;\nfunction conv(a: string | number): string | number\n{...}"
}
]
},
{
"title": "অবজেক্ট",
"items": [{
"definition": "ডিক্লারেশন",
"code": "var person = { \n\tfirstname:\"Tom\",\n\tlastname:\"Hanks\"\n\tsayHello:function() { }\n};\nperson.sayHello = function() {\n\tconsole.log('hello'+person.firstName)\n};\nperson.sayHello();"
},
{
"definition": "প্রোপার্টি এক্সেস করা",
"code": "person.firstname;\nperson.sayHello();"
},
{
"definition": "কন্ডিশনাল প্রপার্টি সহ ডিক্লারেশন",
"code": "var person = { \n\tfirstname:\"Tom\",\n\tlastname?:string,\n} = {firstname: 'Hridoy'}"
},
{
"definition": "কন্ডিশনাল প্রোপার্টি এক্সেস করা",
"code": "console.log(person.lastname?.length)"
}
]
},
{
"title": "ক্লাস",
"items": [{
"definition": "ডিক্লারেশন",
"code": "class Greeter {\n\tgreeting: string;\n\n\tconstructor(message: string) {\n\t\tthis.greeting = message;\n\t}\n\n\tgreet() {\n\t\treturn \"Hello, \" + this.greeting;\n\t}\n}"
},
{
"definition": "পাবলিক মডিফায়ার",
"code": "class Animal {\n\tpublic name: string;\n\tpublic constructor(theName: string) {\n\t\tthis.name = theName;\n\t}\n\tpublic move(distance: number) {\n\t console.log(`${this.name} moved ${distance}m.`);\n\t}\n}"
},
{
"definition": "প্রাইভেট মডিফায়ার",
"code": "class Animal {\n\tprivate name: string;\n\n\tpublic constructor(theName: string) {\n\t\tthis.name = theName;\n\t}\n}"
},
{
"definition": "প্রোটেক্টেড মডিফায়ার",
"code": "class Animal {\n\tprotected name: string;\n\n\tpublic constructor(theName: string) {\n\t\tthis.name = theName;\n\t}\n}"
},
{
"definition": "ক্লাসকে ব্যবহার করা",
"code": "let greeter = new Greeter(\"world\");"
},
{
"definition": "ক্লাসের ইনহেরিটেন্স",
"code": "class Animal {\n\tmove(distance: number = 0) {\n\t console.log(`Animal moved ${distance}m.`);\n\t}\n}\n\nclass Dog extends Animal {\n\tbark() {\n\t\tconsole.log(\"Woof! Woof!\");\n\t}\n}\n\nconst dog = new Dog();\ndog.bark();\ndog.move(10);\ndog.bark();"
},
{
"definition": "এবস্ট্রাক্ট ক্লাস",
"code": "abstract class Animal {\n\n\tabstract makeSound(): void;\n\n\tmove(): void {\n\t\tconsole.log(\"roaming the earth...\");\n\t}\n}"
},
{
"definition": "ক্লাসকে ইন্টারফেসের মতো ব্যবহার করা",
"code": "class Point {\n\tx: number;\n\ty: number;\n}\n\ninterface Point3d extends Point {\n\tz: number;\n}\n\nlet point3d: Point3d = { x: 1, y: 2, z: 3 };"
}
]
},
{
"title": "ইন্টারফেস",
"items": [{
"definition": "ডিক্লারেশন",
"code": "interface ClockInterface {\n\tcurrentTime: Date;\n\tsetTime(d: Date): void;\n}"
},
{
"definition": "ইন্টারফেস ইমপ্লিমেন্ট করা",
"code": "class Clock implements ClockInterface {\n\n\tcurrentTime: Date = new Date();\n\n\tsetTime(d: Date) {\n\t\tthis.currentTime = d;\n\t}\n\n\tconstructor(h: number, m: number) {}\n}"
},
{
"definition": "ইন্টারফেসে ইনহেরিটেন্স",
"code": "interface Child extends Parent, SomeClass {\n\tproperty: Type;\n\toptionalProp?: Type;\n\toptionalMethod?(arg1: Type): ReturnType;\n}"
}
]
},
{
"title": "ইনিউমারেশন বা ইনাম",
"items": [{
"definition": "ডিক্লারেশন",
"code": "enum Role { ADMIN, READ_ONLY, AUTHOR }"
},
{
"definition": "সিরিয়াল অন্য নাম্বার থেকে শুরু করা",
"code": "enum Role { ADMIN = 5, READ_ONLY, AUTHOR }"
},
{
"definition": "নিজের ইচ্ছামত ভ্যালু এসাইন করা",
"code": "enum Role { ADMIN = 'Admin', READ_ONLY = 300, AUTHOR = 250 }"
}
]
},
{
"title": "ডেকোরেটর",
"items": [
{
"definition": "ডিক্লারেশন",
"code": "function food(value: string) {\n\treturn function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {};\n}"
},
{
"definition": "ডেকোরেটর ব্যাবহার করা",
"code": "@food('burger')\n class kitchen {}"
}
]
},
{
"title": "ইউটিলিটি টাইপ",
"items": [{
"definition": "পারশিয়াল বা আংশিক টাইপ",
"code": "interface Person {\n\tname: string;\n\tage: number;\n\theight: string;\n}\n\nconst person1: Partial<Person> = {\n\tname: 'Hridoy',\n\tage: 28\n}"
}]
},
{
"title": "ইন্টারফেস হ্যাকস ও ট্রিকস",
"items": [{
"definition": "অপশনাল প্রোপার্টি ডিক্লেয়ার করা('?' চিহ্ন দিয়ে) ",
"code": "interface PersonInterface {\n\tname:string;\n\tage:number; \n\tprofession?:string;\n}"
},
{
"definition": "উপরের interface থেকে কোনো object বানাতে গেলে profession প্রোপার্টি ছাড়াই বানানো সম্ভব হবে",
"code": "const person1:PersonInterface {\n\n\tname: ='Al Amin Khan',\n\n\tage:23 \n}"
},
{
"definition": "অপশনাল প্রোপার্টি ডিক্লেয়ার না করেই প্রোপার্টি বাদ দেওয়া",
"code": "interface PersonInterface {\n\tname:string;\n\tage:number; \n\tprofession:string;\n}"
},
{
"definition": "Omit<PersonInterface,'property name you want to omit'> হ্যাকস ব্যবহার করে প্রোপার্টি বাদ দেওয়া যায়",
"code": "const person1:Omit<PersonInterface,'profession'> {\n\n\tname: ='Al Amin Khan',\n\n\tage:23 \n}"
}
]
}
]
}