export type MakeActionType = (name: string) => {[key: string]: string}
const combineActionType = <AT extends (MakeActionType | undefined)[]>(...actionTypeList: AT) => (name: string) => {
return actionTypeList.reduce(
(previous, makeActionType) => {
const actionType = makeActionType ? makeActionType(name) : {}
return {
...previous,
...actionType,
}
},
{}
)
}
Now I applied the function above like this:
const abAction = combineActionType((name) => ({a: 'a'}), (name) => ({b: 'b'}))
const ab = abAction('ab')
I would like ab
to contain a
and b
properties, but ab
returns {}
type, that is why ab.a
or ab.b
are not working.
ab.a //err
ab.b //err
How can I define a type of ab that contains both 'a' and 'b' properties?