redux-saga / redux-saga

An alternative side effect model for Redux apps

Home Page:https://redux-saga.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

take(channel) occur error in typescript, how to fix it?

anjunlee opened this issue · comments

commented
import { actionChannel, put, take } from "redux-saga/effects";

function* watchResponse() {
    type resp = { type: string, payload: any }
    const responseChan: resp = yield actionChannel('ORDER_BOOK');
    while (true) {
      const { payload } = yield take(responseChan)
    }
}

export default watchResponse

No overload matches this call.
Overload 1 of 3, '(pattern?: ActionPattern<Action> | undefined): TakeEffect', gave the following error.
Argument of type 'resp' is not assignable to parameter of type 'ActionPattern<Action> | undefined'.
Overload 2 of 3, '(pattern?: ActionPattern<Action> | undefined): TakeEffect', gave the following error.
Argument of type 'resp' is not assignable to parameter of type 'ActionPattern<Action> | undefined'.
Overload 3 of 3, '(channel: TakeableChannel, multicastPattern?: Pattern | undefined): ChannelTakeEffect', gave the following error.
Argument of type 'resp' is not assignable to parameter of type 'TakeableChannel'.
Property 'take' is missing in type 'resp' but required in type 'TakeableChannel'.ts(2769)
index.d.ts(247, 3): 'take' is declared here.

Your type annotation is wrong, it should be:

const responseChan: Channel<resp> = yield actionChannel('ORDER_BOOK');
commented

Your type annotation is wrong, it should be:

const responseChan: Channel<resp> = yield actionChannel('ORDER_BOOK');

thanks, it's working