I have this data structure :
type FirstOne = {
type: 'first-one',
uniqueKey1111: 1,
};
type FirstTwo = {
type: 'first-two',
uniqueKey2222: 2,
}
type First = {
type: 'first',
details: FirstOne | FirstTwo
}
type SecondOne = {
type: 'second-one',
uniqueKey3: 3,
};
type SecondTwo = {
type: 'second-two'
};
type Second = {
type: 'second',
details: SecondOne | SecondTwo,
}
type DataType = First | Second;
data have type and subtype, if I select first type don't can select second-one subtype,
I have on page two select, first refer to Data.type, second to Data.details.type I need validate select options:
I have next generic for convert type DataType to SelectOption:
type SelectOption<T> = { name: string, value: T };
I don't known how validate additional options what it's value depend of main select options
type SelectOptions = {
main: SelectOption<DataType['type']>[],
additional: SelectOption<DataType['details']['type']>[];
}
const options : SelectOptions = {
main: [{name: 'name', value: 'first'}],
additional: [{name: '', value: 'second-two'}],
}
in options now set invalid data, but typescript not check what additionalOptions have option what not compatible with main.
Also I think currently SelectOptions structure don't can exec this checking.
I will be grateful for any idea to solve the problem
I realize what options need have next structure
const options = {
main: [{name: 'name', value: 'first'}, {name: 'name', value: 'second'}],
additional: {
first: [{name: '', value: 'first-one'}, {name: '', value: 'first-two'}],
second: [{name: '', value: 'second-one'}, {name: '', value: 'second-two'}]
},
};