jeffbski / redux-logic

Redux middleware for organizing all your business logic. Intercept actions and perform async processing.
MIT License
1.81k stars 107 forks source link

[0.15.3] Typescript Error: Undefined does not meet it's constraint 'object' #115

Closed chmaltsp closed 6 years ago

chmaltsp commented 6 years ago

Hello

Thanks for getting the typescript typings in. Maybe I am doing something wrong, but when using 2.9.2 you cannot extend an object and set the default to undefined screen shot 2018-08-07 at 10 50 22 am

Setting changing the definition to

export type ArgumentAction<
  Type extends string = string,
  Payload extends object = {},
  Meta extends object = {}
> = ActionBasis<Type> & Partial<Action<string, object, object>>;

helps but then action.payload ends up being undefined in createLogic({ process({ action }}). I'm still kind of new to TS but this prevents the project form building! @alvis maybe you know more about this?

alvis commented 6 years ago

@chmaltsp Thanks for reporting. I apologise as I forgot this syntax will cause a problem with "strictNullChecks". The reason of using the undefined type is to take the advantage of the news conditional type, so that for example if the payload is set to 'undefined', the resulting action object would not have a payload field.

I'm working on a fix on it and would make a PR soon.

chmaltsp commented 6 years ago

@alvis Thank you! I was playing around with it a bit more and I also noticed that in a true FSA payload and meta should actually be any. In my app sometimes the payload is just a string.

alvis commented 6 years ago

@chmaltsp #117 should now resolve the problem.

Also thanks for pointing out the recommended types for payload and meta too. I'm working on it.

jeffbski commented 6 years ago

Thanks to all for reporting and especially for @alvis for the TS fixes. It is published in v0.15.4

gustavopch commented 5 years ago

@chmaltsp #117 should now resolve the problem.

Also thanks for pointing out the recommended types for payload and meta too. I'm working on it.

@alvis @jeffbski As the comment above says, typings for payload and meta should extend any, but they still extend object | undefined.