aikoven / typescript-fsa-redux-saga

TypeScript FSA utilities for redux-saga
MIT License
61 stars 4 forks source link

Can not use null types async actions with bindAsyncAction #9

Closed Zyets closed 5 years ago

Zyets commented 6 years ago

Here is the modified example from your Readme. The only changes i've made are the types i'm passing to actionCreator.async:

import {SagaIterator} from 'redux-saga';
import {call} from 'redux-saga/effects';
import actionCreatorFactory from 'typescript-fsa';
const fetchSomething = () => {};
const actionCreator = actionCreatorFactory();

export const doSomething = actionCreator.async<{foo: string}, null>('DO_SOMETHING');

const doSomethingWorker = bindAsyncAction(doSomething)(
    function* (params): SagaIterator {
        // `params` type is `{foo: string}`
        yield call(fetchSomething, params.foo);
        return null;
    },
);

function* mySaga(): SagaIterator {
    yield call(doSomethingWorker, {foo: 'lol'});
}

I dont get any data for success action from my fetch function, and i dont need any, so i pass null as a second type-parameter.

But as i do so, i get this:

ERROR: Property 'result' is optional in type '{ params: { foo: string; }; } & { result?: null; }' but required in type 'Success<{ foo: string; }, null>'.

Same behaviour with undefined.

Also i can not pass single type-param to actionCreator.async function... it needs two.

What should i do? Or am i doing smth wrong?

Thanks!

aikoven commented 5 years ago

Sorry for the late response.

Which version of typescript-fsa do you use? If it is 3.0.0-beta-something, try to downgrade to 2.5.0. There are still some unsolved problems with typings in 3.0.0.

Zyets commented 5 years ago

Thank you!

I'll try this solution and leave feedback later.. currently working on another project!