/ examples / simple.ts
simple.ts
 1  import { deserialize, rename, t } from "../src";
 2  
 3  class NestedModel {
 4    value = t.boolean();
 5  }
 6  
 7  class MyModel {
 8    id = t.number();
 9  
10    @rename("user_name")
11    name = t.string();
12  
13    @rename("nested_hehe")
14    nested = t.reference(NestedModel);
15  
16    thisIsNeverGiven = t.option(t.string());
17  
18    sayHello(): void {
19      console.log(`Hello, ${this.name} ; ID: ${this.id}`);
20    }
21  }
22  
23  const model = deserialize(MyModel, {
24    id: 2,
25    nested_hehe: {
26      value: true
27    },
28    user_name: "Mikkel"
29  });
30  
31  console.log(model);
32  model.sayHello();