I'm trying to figure out how can I define a type of array contains objects array and array or objects keys as elements :
export type iFormInputTest = {
name: string
type: 'textInput' | 'Select'
}
export type iFormInputsTest= {
button: {
label: string
style?: { [key: string]: any }
}
data: iFormInputTest[] | iFormInputTest[][]
}
const inputs: iFormInputsTest = {
button: {
label: 'Submit'
},
data: [
{
name: 'input1',
type: 'textInput'
},
[
{
name: 'input2',
type: 'textInput'
},
{
name: 'input3',
type: 'Select'
}
],
{
name: 'input4',
type: 'textInput'
}
]}
This is the type error I get :
Type '({ name: string; type: "textInput"; } | ({ name: string; type: "textInput"; } | { name: string; type: "Select"; })[])[]' is not assignable to type 'iFormInputTest[] | iFormInputTest[][]'. Type '({ name: string; type: "textInput"; } | ({ name: string; type: "textInput"; } | { name: string; type: "Select"; })[])[]' is not assignable to type 'iFormInputTest[]'. Type '{ name: string; type: "textInput"; } | ({ name: string; type: "textInput"; } | { name: string; type: "Select"; })[]' is not assignable to type 'iFormInputTest'. Type '({ name: string; type: "textInput"; } | { name: string; type: "Select"; })[]' is missing the following properties from type 'iFormInputTest': name, type
I tried everything but I wasn't able to find a way to define a data key holds both array of iFormInputTest objects and recursive array of iFormInputTest