...
Code Block | ||
---|---|---|
| ||
export type Settings = { enabled: false; } | { /** * @title Enabled * @default false */ enabled: true; /** * @title Some variable * @default “some-value” */ some_variable: string; }; |
Example with array of item:
Code Block |
---|
interface Item{
/**
* @title Name
* @default ""
*/
name: string;
/**
* @title Code
* @default ""
*/
code: string;
}
interface Items extends Array<Item>{}
export type Settings = { enabled: false } | {
/**
* @title Enabled
*/
enabled: true;
items: Items;
} |
Note the conditional type here. In this example an instance of type Settings
may have one of 2 interfaces: either enabled
field has a value of false
, or it is true
and then some_variable
field is required. When a settings form is rendered that would mean that some_variable
field will be hidden, unless enabled
field has a value of true
(it will be rendered as a checkbox, so the checkbox must be checked).
...