Registry /
type-stubs / typescript-fsa-redux-saga
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
bindAsyncAction
✓ import { bindAsyncAction } from 'typescript-fsa-redux-saga';
✗ import bindAsyncAction from 'typescript-fsa-redux-saga';
This is the primary named export for the library's core functionality.
actionCreatorFactory
✓ import actionCreatorFactory from 'typescript-fsa';
✗ import { actionCreatorFactory } from 'typescript-fsa';
Essential for creating async action creators used by `bindAsyncAction`. It is a default export from the `typescript-fsa` library.
SagaIterator
✓ import { SagaIterator } from 'redux-saga';
✗ import SagaIterator from 'redux-saga';
The primary return type for Redux Saga generators, commonly used when defining worker sagas wrapped by `bindAsyncAction`.
Demonstrates how to define an async action using `typescript-fsa` and then wrap a `redux-saga` worker with `bindAsyncAction` to automatically handle `started`, `done`, and `failed` dispatches, illustrating the type-safe flow.
import actionCreatorFactory from 'typescript-fsa';
import { SagaIterator } from 'redux-saga';
import { call } from 'redux-saga/effects';
import { bindAsyncAction } from 'typescript-fsa-redux-saga';
// actions.ts (excerpt)
const actionCreator = actionCreatorFactory('MY_APP');
export const doSomething =
actionCreator.async<{foo: string}, // parameter type
{bar: number} // result type
>('DO_SOMETHING');
// A mock API call function
async function fetchSomething(param: string): Promise<number> {
console.log(`Simulating API call with: ${param}`);
return new Promise(resolve => setTimeout(() => resolve(param.length * 10), 500));
}
// The worker saga wrapped by bindAsyncAction
const doSomethingWorker = bindAsyncAction(doSomething)(
function* (params): SagaIterator<{bar: number}> {
// `params` type is `{foo: string}`
console.log(`Worker saga started with params:`, params);
const result = yield call(fetchSomething, params.foo);
console.log(`API call returned:`, result);
return {bar: result};
},
);
// A root saga that demonstrates calling the async worker
function* myRootSaga(): SagaIterator {
console.log('Initiating doSomething action...');
// Calling the worker directly. bindAsyncAction internally dispatches
// doSomething.started, doSomething.done (or doSomething.failed if an error occurs).
const result = yield call(doSomethingWorker, {foo: 'example_data'});
console.log('doSomethingWorker completed with result:', result);
try {
console.log('Initiating another doSomething action (simulating potential error path)...');
yield call(doSomethingWorker, {foo: 'error_case'}); // For demo, assuming this could lead to error
} catch (e) {
console.error('Caught an error in saga outside worker:', e); // Errors from worker are re-thrown by bindAsyncAction
}
}
// To run this in a Redux Saga setup, you would typically pass `myRootSaga` to `sagaMiddleware.run`.
// Example (for conceptual understanding, not directly executable without Redux setup):
// import createSagaMiddleware from 'redux-saga';
// import { createStore, applyMiddleware } from 'redux';
// const sagaMiddleware = createSagaMiddleware();
// const store = createStore(() => ({}), applyMiddleware(sagaMiddleware));
// sagaMiddleware.run(myRootSaga);
Errors
Common errors & fixes
TypeError: (0 , typescript_fsa_1.actionCreatorFactory) is not a function
Mismatched major versions between `typescript-fsa-redux-saga` and `typescript-fsa`. `typescript-fsa-redux-saga@2.x` requires `typescript-fsa@3.x`.
fixEnsure `typescript-fsa` is installed at version `^3.0.0` or later (`npm install typescript-fsa@^3`).
Error: Could not find type definition for 'redux-saga'
`redux-saga` or its type definitions (`@types/redux-saga`) are not installed, or there's a version mismatch.
fixInstall `redux-saga` and its type definitions: `npm install redux-saga @types/redux-saga`.
Audit
Dependencies
typescript-fsarequiredRequired for creating FSA-compliant, type-safe action creators, which this package extends.
redux-sagarequiredThe core library for managing side effects, which this package integrates with.