Validating types
You can also use JSDocs to further validate your types. This is especially useful to validate emails, numbers ranges, string lengths, dates, and more.
Read all available @<keyword>s:
ts
export interface Example {
/**
* @minLength 3
* @maxLength 20
*/
name: string;
/** @format email */
email: string;
/**
* @minimum 0
* @maximum 150
*/
age: number;
/**
* @minItems 1
* @maxItems 10
* @uniqueItems
*/
items: string[];
/**
* @minProperties 1
* @maxProperties 10
*/
properties: Record<string, string>;
}1
2
3
4
5
6
2
3
4
5
6
json
{
// ...
"Example": {
"type": "object",
"additionalProperties": false,
"required": ["name", "email", "age", "items", "properties"],
"properties": {
"age": {
"maximum": 150,
"minimum": 0,
"type": "number"
},
"email": {
"format": "email",
"type": "string"
},
"items": {
"items": {
"type": "string"
},
"maxItems": 10,
"minItems": 1,
"type": "array",
"uniqueItems": true
},
"name": {
"maxLength": 20,
"minLength": 3,
"type": "string"
},
"properties": {
"additionalProperties": {
"type": "string"
},
"maxProperties": 10,
"minProperties": 1,
"type": "object"
}
}
}
}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
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