Hi I would like to index object interface with a variable
so heres my interfaces:
interface OptionsRedux {
default_route: DefaultRoute[];
insurance_company: InsuranceCompany[];
marital_status: MaritalStatus[];
reason: Reason[];
termination_reason: TerminationReason[];
}
type optionGroupTypes = keyof OptionsRedux;
Right now my code looks like this:
interface GetOptions {
type: ActionTypes.getOptions,
payload: {group: optionGroupTypes, values: OptionsRedux[optionGroupTypes]}
}
export const getOptions = (
group: optionGroupTypes,
values: OptionsRedux[optionGroupTypes]
): GetOptions => ({
type: ActionTypes.getOptions,
payload: { group, values },
});
which gives me type for payload value:
DefaultRoute[] | InsuranceCompany[] | MaritalStatus[] | Reason[] | TerminationReason[]
but I would like to do something like this:
interface GetOptions {
type: ActionTypes.getOptions,
payload: {group: optionGroupTypes, values: OptionsRedux[group]}
}
this gives me that the group is undefined.
my objective is, that when I would use function getOption("default_route", values), the values would have to be:
DefaultRoute[]
Any ideas? cant find anything that would work
This is the right way to create a partial interface
Create an object of type IPerson
I hope this will help you