jfairbank / redux-saga-test-plan

Test Redux Saga with an easy plan.
http://redux-saga-test-plan.jeremyfairbank.com
MIT License
1.25k stars 127 forks source link

Fix the typing of effects that take Channels #313

Closed kristenmills closed 4 years ago

kristenmills commented 4 years ago

Use TakeableChannel and FlushableChannel instead of Channel in effect typings.

Example that this fixes

export function* mySaga() {
  const chan = yield call(makeChannel);

  try {
    while (true) {
      const act = yield take(chan);
      yield put(act);
    }
  } finally {
    if (yield cancelled()) {
      chan.close();
    }
  }
}

const makeChannel = () => eventChannel(emit => {
  emit({ type: 'Hello' })
  return () => { };
});

const channel = makeChannel();

const saga = testSaga(mySaga)
  .next().call(makeChannel)
  // Error happens here
  // Property 'put' is missing in type 'EventChannel<unknown>' but required in type 'Channel<unknown>'
  .next(channel).take(channel)
codecov-io commented 4 years ago

Codecov Report

Merging #313 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #313   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files          22       22           
  Lines         748      748           
  Branches      154      154           
=======================================
  Hits          745      745           
  Misses          3        3

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7358c5f...1d3921d. Read the comment docs.

jp928 commented 4 years ago

@kristenmills Many thanks for your PR.