forked from kulshekhar/typescript-reflection-difference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.ts
45 lines (38 loc) · 952 Bytes
/
sample.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
/*
* Test issue for class-transformer/ts-jest
*/
import "reflect-metadata";
import { plainToClass, Type } from "class-transformer";
export class Weapon {
constructor(public model: string,
public range: number) {
}
}
export class User {
public id: number;
public name: string;
@Type(() => Weapon)
public weapons: Map<string, Weapon>;
}
export const plainUser = {
id: 1,
name: "Max Pain",
weapons: {
firstWeapon: {
model: "knife",
range: 1,
},
secondWeapon: {
model: "eagle",
range: 200,
},
thirdWeapon: {
model: "ak-47",
range: 800,
},
},
};
const classedUser = plainToClass(User, plainUser);
console.log("classedUser is instance of User?", classedUser instanceof User);
console.log("classedUser.weapons is instance of Map?", classedUser.weapons instanceof Map);
console.log("classedUser.weapons is instance of Weapon?", classedUser.weapons instanceof Weapon);