-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.ts
66 lines (53 loc) · 1.54 KB
/
demo.ts
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
@classDec
@classDecFactory('class decorator factory')
class User {
@propertyDec
firstName: string;
@propertyDecFactory('property decorator factory')
lastName: string;
constructor(firstName: string, lastName: string) {
this.firstName = firstName;
this.lastName = lastName;
}
@methodDec
@methodDecFactory('method decorator factory')
printName(
@paramDec middleName?: string,
@paramDecFactory('parameter decorator factory') nickName?: string
) {
console.log('User name is ' + this.firstName + ' ' + middleName + this.lastName + '\n');
if (nickName) console.log('NickName is ' + nickName);
}
}
function classDec<TFunction extends Function>(target: TFunction): TFunction | void {
// a dummy funtion
}
function classDecFactory(name: string) {
printEvaludated(name);
return classDec;
}
function propertyDec(target: Object, propertyKey: string) {
// a dummy funtion
}
function propertyDecFactory(name: string) {
printEvaludated(name);
return propertyDec;
}
function methodDec(target: Object, propertyKey: string, desp: PropertyDescriptor): PropertyDescriptor | void {
// a dummy funtion
}
function methodDecFactory(name: string) {
printEvaludated(name);
return methodDec;
}
function paramDec(target: Object, propertyKey: string, paramIndex: number) {
// a dummy funtion
}
function paramDecFactory(name: string) {
printEvaludated(name);
return paramDec;
}
/** Util functions */
function printEvaludated(factoryName: string) {
console.log(factoryName + ' evaluated');
}