Skip to content

Commit dea10ae

Browse files
committed
typescript content
1 parent a3cb5b4 commit dea10ae

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

_data/toc.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,24 @@ es6:
204204
- path: /javascript-developer/es/resource/
205205
title: resources
206206

207+
typescript:
208+
- sectiontitle:
209+
section:
210+
- path: /javascrip-developer/typescript/
211+
title: Typescript intro
212+
- path: /javascrip-developer/typescript/types/
213+
title: Type
214+
- path: /javascrip-developer/typescript/enum/
215+
title: Enum
216+
- path: /javascrip-developer/typescript/type-alias/
217+
title: Type alias
218+
- path: /javascrip-developer/typescript/generic/
219+
title: Generic
220+
- path: /javascrip-developer/typescript/decorator/
221+
title: Decorator
222+
- path: /javascrip-developer/typescript/resources/
223+
title: Resources
224+
207225

208226
vue:
209227
- sectiontitle: Basic React
Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
11
---
2-
description: decorator typescript
2+
description: A decorator is a function that takes in a target object.
33
keywords: node.js, js, typescript, ts
4-
title: decorator typescript
4+
title: typescript decorator
55
toc_max: 4
66
---
77

88
## decorator
99

10+
In TypeScript, a decorator is a function that takes in a target object (such as a class, method, or property) and returns a new object with the same structure, but possibly enhanced with additional features. Decorators are a language feature that allows you to annotate and modify classes and class members at design time.
11+
12+
13+
1014
`@` represent decorator `@test`
1115

16+
# method decorator
17+
18+
```ts
19+
function auth(){
20+
return function (target: any, key: any, descriptor: PropertyDescriptor){
21+
let fn = descriptor.value
22+
let isAuth: boolean = false
23+
if (isAuth){
24+
descriptor.value = (...args: any) => {
25+
let f = fn(...args)
26+
return f
27+
}
28+
} else {
29+
descriptor.value = () => {
30+
return "login required"
31+
}
32+
}
33+
}
34+
}
35+
36+
class User{
37+
@auth()
38+
profile(name: string){
39+
return("profile: " + name)
40+
}
41+
}
42+
43+
let user: any = new User()
44+
console.log(user.profile('kamal'))
45+
```
46+
1247
# resources
1348

14-
* https://www.typescriptlang.org/docs/handbook/decorators.html
15-
* https://gist.github.com/remojansen/16c661a7afd68e22ac6e
49+
* [decorator official](https://www.typescriptlang.org/docs/handbook/decorators.html)
50+
* [gist remojansen](https://gist.github.com/remojansen/16c661a7afd68e22ac6e)
51+
* [class decorator](https://dev.to/danywalls/decorators-in-typescript-with-example-part-1-m0f)
52+
* [decorator youtube - Ben Awad ***
53+
](https://www.youtube.com/watch?v=bRAcWk9S-6g)
54+
* [decorator codeburst ***](https://codeburst.io/decorate-your-code-with-typescript-decorators-5be4a4ffecb4)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
description: Typescript best resources lists.
3+
keywords: node.js, js, typescript, ts
4+
title: Typescript resources
5+
toc_max: 4
6+
---
7+
8+
# documentations and contents
9+
10+
* [official doc](https://www.typescriptlang.org/docs/handbook/classes.html)
11+
* [playground](https://www.typescriptlang.org/play)
12+
* [educative](https://www.educative.io/blog/typescript-tutorial)
13+
* [typescripttutorial](https://www.typescripttutorial.net/typescript-tutorial/typescript-object-type/)
14+
* [cheatsheet by rmolinamir](https://github.com/rmolinamir/typescript-cheatsheet)
15+
16+
17+
## Video
18+
19+
* [TheNetNinja](https://www.youtube.com/playlist?list=PL4cUxeGkcC9gUgr39Q_yD6v-bSyMwKPUI)
20+
21+
* <a href="https://www.youtube.com/playlist?list=PLzvRQMJ9HDiQyjtcrtvDkeQMJIrv5ABbm" target="_blank">Video Tutorial</a>
22+
23+
* <a href="https://www.youtube.com/playlist?list=PL6tu16kXT9Pp6XV3L3lrWideBW6Mcwaa5" target="_blank">Video Tutorial 2</a>

javascript-developer/typescript/types.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,23 @@ let isResult: string = `welcome to ${isDanger}`;
2424
let isDanger: number[] = [1, 3, 5, 7];
2525
let isDanger: Array<number> = [1, 3, 5, 7];
2626

27+
# Array of objects
28+
let employees: Array<{name: string, age: number, [key: string]: any}> = [
29+
{ name: 'kamal', age: 26 },
30+
{ name: 'mostafa', age: 21}
31+
]
32+
33+
# Array of objects
34+
let employees: {name: string, age: number}[] = [
35+
{ name: 'kamal', age: 26 },
36+
{ name: 'mostafa', age: 21}
37+
]
38+
2739
# any
2840
let isDanger: any = "this is kamal"
2941
```
3042
3143
# resources
3244
* [typescripttutorial](https://www.typescripttutorial.net/typescript-tutorial/typescript-object-type/)
45+
* [array of objects stackoverflow](https://stackoverflow.com/questions/35435042/how-can-i-define-an-array-of-objects)
3346
* <a href="https://youtu.be/Q6pePpv-C-E" target="_blank">Video Tutorial</a>

0 commit comments

Comments
 (0)