-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme-types-example.ts
43 lines (37 loc) · 1.28 KB
/
readme-types-example.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
import { DTObject } from "./src/dt-object";
import { ArrayField } from "./src/fields/array-field";
import { BooleanField } from "./src/fields/boolean-field";
import { DateTimeField } from "./src/fields/date-time-field";
import { StringField } from "./src/fields/string-field";
import { CombineField } from "./src/fields/combine-field";
import { NumberField } from "./src/fields/number-field";
class UserDto extends DTObject {
name = StringField.bind()
nickName = StringField.bind({ required: false })
birthday = DateTimeField.bind()
active = BooleanField.bind({ default: true })
hobbies = ArrayField.bind({ items: StringField.bind() })
favoriteColor = StringField.bind({ allowNull: true })
}
async function t() {
const userDto = await UserDto.parse({
name: "Michael Scott",
birthday: '1962-08-16',
hobbies: ["Comedy", "Paper"],
favoriteColor: "Red"
});
userDto.name
userDto.nickName
userDto.birthday
userDto.active
userDto.hobbies
userDto.favoriteColor
class InventoryItem extends DTObject {
quantity = CombineField.bind({
anyOf: [
NumberField.bind({ minValue: 1, maxValue: 10 }),
NumberField.bind({ minValue: 50, maxValue: 100 })
]
})
}
}