-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
70 lines (55 loc) · 1.29 KB
/
index.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
67
68
69
70
import { AbstractSerializer } from './abstract-serializer';
import { AutoSerialize } from './auto-serialize';
import { MapTo } from './mapto';
export {
AbstractSerializer,
AutoSerialize,
MapTo,
}
@AutoSerialize
export class Address extends AbstractSerializer {
house = '123';
street = 'xyz';
city = 'Peshawar';
constructor() {
super();
}
fullAddress() {
return `${this.house} ${this.street} ${this.city}`;
}
}
@AutoSerialize
export class Todo extends AbstractSerializer {
id: number = 0;
text: string = 'First';
desc: string = 'first todo description';
ids: number[] = [];
@MapTo({ type: Address }) address: Address = new Address();
@MapTo({ type: [Address] }) list: Address[] = [];
constructor() {
super();
}
get displayString() { return 'some string'; }
display() {
console.log('function');
}
}
const todo = new Todo().setValues({
text: 'again',
address: {
house: 'new house',
street: 'new street',
},
list: [
{
house: 'new house',
street: 'new street',
},
{
house: 'new house',
street: 'new street',
},
],
ids: [1, 2, 3, 4, 4],
}) as Todo;
console.log(todo.getValues());