Giter Site home page Giter Site logo

Comments (7)

tomekkleszcz avatar tomekkleszcz commented on June 12, 2024

@chmac Can you also attach a block of code where you define actionCreator?

from redux-saga-promise-actions.

chmac avatar chmac commented on June 12, 2024

@tomekkleszcz Yep, sorry, original example wasn't clear at all, I updated it. The actionCreator as it was is a PromiseAction.request. I've added that to make it clearer.

from redux-saga-promise-actions.

tomekkleszcz avatar tomekkleszcz commented on June 12, 2024

@chmac I don't use redux-typed-saga in my projects. I've checked out this library and this is a declaration for putResolve function:

export function putResolve<A extends Action>(
  action: A,
): SagaGenerator<A, PutEffect<A>>;

As you can see the return value typed as the action which is provided as the argument of the putResolve function which in your case totally incorrect - you provide actionCreators.request() and you would expect the return value to be {token: 'string'}, but it is the type of the action you provide instead.

There are three solutions to this problem:

  1. Use putResolve from redux-saga
  2. Update dispatch helper in my library to type the return type correctly
  3. Create a PR to typed-redux-saga and fix the problem

I advise you to use the first solution for now. As soon as I close other feature requests I think I may start to work on updating dispatch helper.

from redux-saga-promise-actions.

chmac avatar chmac commented on June 12, 2024

@tomekkleszcz Thanks for taking the time to look at this for me, I appreciate it.

I started out using putResolve() from redux-saga, but in that case I get the type of val as unknown. The trick typed-redux-saga uses is to use yield* instead of yield and then a babel macro to transform the whole thing at runtime. As I understand it, the issue is that TypeScript has no way of knowing what that the Redux Saga middleware will resolve into the yield call.

I also tried the dispatch helper from your package, again I get type unknown for val.

Do you have an example of how I could use putResolve from redux-saga, or preferably, your dispatch function and have TypeScript know what the type of val will be? That would be the best case, I could drop the typed-redux-saga package altogether.

from redux-saga-promise-actions.

tomekkleszcz avatar tomekkleszcz commented on June 12, 2024

I think in your case the following solution would work:

import {putResolve} from 'redux-saga'

const actionCreators = createPromiseAction(
  "foo/request",
  "foo/success",
  "foo/failure"
)<undefined, { token: "string" }, { error: Error }>();

function* saga() {
  const val: { token: "string" } = yield putResolve(actionCreators.request());
}

from redux-saga-promise-actions.

chmac avatar chmac commented on June 12, 2024

@tomekkleszcz Yeah, I can typecast the return value. But if I get the type wrong, there's no checking. That's the aim of the typed-redux-saga package, to avoid that potential mistake.

OK, thanks a lot for all the input. I'll try digging further into the putResolve types from redux-typed-saga, it's definitely not an issue in your package. I actually get the correct type, just that the putResolve() type definition in typed-redux-saga doesn't understand that it should take the ResolveType and not the whole thing.

Thanks again for the help on this. 👍 👍 👍

from redux-saga-promise-actions.

chmac avatar chmac commented on June 12, 2024

@tomekkleszcz Looking at this fresh today, I realise that I think the typing in the typed-redux-saga (and not the redux-typed-saga) package is wrong for putResolve(). I opened an issue. Thanks again for the help, closing this as it's not an issue in this package I realise.

from redux-saga-promise-actions.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.