redux-logic
redux-logic copied to clipboard
Why is CreateLogic.Config.Transform.Hook uses optional argument for reject?
When compiling with tsc and --strict
switched on, I found error in createLogic
callback. Specifically, tsc indicates reject
parameter in transform
function can be undefined. I checked the type definition:
https://github.com/jeffbski/redux-logic/blob/4b0951af03dbe3097e4bad5710fe274c2f3f1e6b/definitions/logic.d.ts#L216-L240
It used reject?: Pass<Action, Context>
for transform
function signature. I wonder, is there any case where transform
can be called with reject
neglected? I've checked #124 and #125, but still couldn't figure out why there is ?
following reject
parameter.
The reason that reject
is optional in the signature is that transform
and validate
are just aliases for the same method. validate would necessarily need allow/next and reject. The reason for both is simply to better communicate the intent. Reject wouldn't usually be needed in a transform use case, but left as optional to mirror the validate signature.
The reason that reject is optional in the signature is that transform and validate are just aliases for the same method.
If I've got this correct, transform
and validate
are actually the same callback.
https://github.com/jeffbski/redux-logic/blob/4b0951af03dbe3097e4bad5710fe274c2f3f1e6b/src/createLogic.js#L175-L177
In this case, I think it would be better if you either
- make
reject
intransform
a non-optional parameter, so when I'm implementing the callback, I do not need to write something like
if (reject) {
reject(action);
}
because there is actually no case where reject
is null
, but I will need to make tsc happy. However, you may write some @deprecate
notice in tsdoc or some runtime warning to tell me do not use transform
for rejct
.
- just remove
reject
parameter in.d.ts
fortransform
, so to force me to choosevalidate
callback because it has a non-optionalreject
parameter
https://github.com/jeffbski/redux-logic/blob/4b0951af03dbe3097e4bad5710fe274c2f3f1e6b/definitions/logic.d.ts#L201-L212