Skip to content

Commit ff68298

Browse files
committed
Updated types for CustomMetadataField
1 parent 6515511 commit ff68298

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

libs/interfaces/CustomMetatadaField.ts

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,67 @@
1-
export interface CustomMetadataFieldSchema {
2-
type: string;
3-
selectOptions?: (string | number | boolean)[];
4-
defaultValue?: string | number | boolean | (string | number | boolean)[];
5-
isValueRequired?: boolean;
6-
minValue?: string | number;
7-
maxValue?: string | number;
1+
type RequiredSchema<T> = {
2+
isValueRequired: true;
3+
defaultValue: T;
4+
} | {
5+
isValueRequired?: false;
6+
defaultValue?: T;
7+
};
8+
9+
type CustomMetadataTextField = RequiredSchema<string> & {
10+
type: "Text";
811
minLength?: number;
912
maxLength?: number;
10-
}
13+
};
1114

12-
export interface CustomMetadataFieldSchemaMinusType {
13-
selectOptions?: (string | number | boolean)[];
14-
defaultValue?: string | number | boolean | (string | number | boolean)[];
15-
isValueRequired?: boolean;
16-
minValue?: string | number;
17-
maxValue?: string | number;
15+
type CustomMetadataTextareaField = RequiredSchema<string> & {
16+
type: "Textarea";
1817
minLength?: number;
1918
maxLength?: number;
20-
}
19+
};
20+
21+
type CustomMetadataNumberField = RequiredSchema<number> & {
22+
type: "Number";
23+
minValue?: string | number;
24+
maxValue?: string | number;
25+
};
26+
27+
type CustomMetadataDateField = RequiredSchema<number> & {
28+
type: "Date";
29+
minValue?: string | number;
30+
maxValue?: string | number;
31+
};
32+
33+
type CustomMetadataBooleanField = RequiredSchema<Boolean> & {
34+
type: "Boolean";
35+
};
36+
37+
type CustomMetadataSingleSelectField = RequiredSchema<Array<string | boolean | number>> & {
38+
type: "SingleSelect";
39+
selectOptions: Array<string | boolean | number>;
40+
};
41+
42+
type CustomMetadataMultiSelectField = RequiredSchema<Array<string | boolean | number>> & {
43+
type: "MultiSelect";
44+
selectOptions: Array<string | boolean | number>;
45+
};
46+
47+
export type CustomMetadataFieldSchema =
48+
| CustomMetadataTextField
49+
| CustomMetadataTextareaField
50+
| CustomMetadataNumberField
51+
| CustomMetadataDateField
52+
| CustomMetadataBooleanField
53+
| CustomMetadataSingleSelectField
54+
| CustomMetadataMultiSelectField;
55+
56+
export type CustomMetadataFieldSchemaMinusType =
57+
| Omit<CustomMetadataTextField, "type">
58+
| Omit<CustomMetadataTextareaField, "type">
59+
| Omit<CustomMetadataNumberField, "type">
60+
| Omit<CustomMetadataDateField, "type">
61+
| Omit<CustomMetadataBooleanField, "type">
62+
| Omit<CustomMetadataSingleSelectField, "type">
63+
| Omit<CustomMetadataMultiSelectField, "type">;
64+
2165
/**
2266
* Create a new custom metadata field
2367
*

0 commit comments

Comments
 (0)