createAction's 4th type is supposed to be an array - is it really required?
hsz opened this issue · comments
After the latest release, there is createAction
available with the following typing:
createAction<
TType extends TypeConstant,
TCreatorPayload extends any = undefined,
TCreatorMeta extends any = undefined,
TArgs extends any[] = any[]
>
So now if I'd like to specify all of the types, I need to:
const myAction = createAction<TypeConstant, { foo: string }, { bar: string }, string[]>(
'MY_ACTION',
arg => ({ foo: arg }),
arg => ({ bar: arg }),
)();
myAction('hi!');
So - to define the arg
type (and myAction
arguments as well) as string
I need to provide string[]
.
Is it really necessary? It looks like a fake requirement, because it can be handled like:
export function createAction<
TType extends TypeConstant,
TCreatorPayload extends any = undefined,
TCreatorMeta extends any = undefined,
TArgs extends any = undefined
>(
type: TType,
payloadCreator: undefined | ((...args: TArgs[]) => TCreatorPayload),
metaCreator?: (...args: TArgs[]) => TCreatorMeta
): <
TPayload extends TCreatorPayload = TCreatorPayload,
TMeta extends TCreatorMeta = TCreatorMeta
>() => (...args: TArgs[]) => ActionBuilder<TType, TPayload, TMeta>;
What do you think?
Hey @hsz,
It is not a false requirement its purpose is to get an inference in case of payload/meta creators with multiple parameters, here is a comparison before and after your change:
BEFORE:
AFTER:
That makes sense. Thank you for the explanation and delivering the v5!