Registry / type-stubs / typescript-fsa-redux-saga

typescript-fsa-redux-saga

JSON →
library2.0.0jsnpmunverified

This package provides utility functions to seamlessly integrate asynchronous action creators from `typescript-fsa` with `redux-saga` worker sagas. Its primary function, `bindAsyncAction`, simplifies handling the lifecycle of async operations by automatically dispatching `started`, `done`, and `failed` actions around a saga's execution. This ensures strong type safety throughout the asynchronous flow when using `typescript-fsa`'s action patterns. The current stable version is 2.0.0, which notably requires `typescript-fsa` version 3.x.x. The project actively maintains compatibility with recent `redux-saga` releases, providing a reliable bridge between these two popular libraries for typed state management and side-effect handling.

npm install typescript-fsa-redux-saga
INSTALL
IMPORT
SIG · TYPESCRIPT-FSA-RED
T
typescript-fsa-redux-saga
type-stubsjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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);
Debug
Known issues
breakingVersion 2.0.0 upgraded the `typescript-fsa` dependency to `^3.0.0`. Users on `typescript-fsa` v2.x.x must upgrade their `typescript-fsa` package to version 3 or higher, or remain on `typescript-fsa-redux-saga` v1.x.x.
fix
Upgrade `typescript-fsa` to `^3.0.0` (`npm install typescript-fsa@^3`) or pin `typescript-fsa-redux-saga` to a version less than 2.0.0.
affects: >=2.0.0
gotchaPrior to v1.0.3, generator transpilation had inconsistencies across CommonJS and ES6 builds, sometimes using Babel. From v1.0.3 onwards, Babel was removed, and native TypeScript transpilation is used for generators. This might affect projects with highly customized Babel configurations or those relying on previous specific generator output.
fix
Ensure your TypeScript compiler (`tsconfig.json`) is correctly configured for generator transpilation, particularly `target` and `lib` settings, and remove any legacy Babel configurations specific to `typescript-fsa-redux-saga` if present.
affects: >=1.0.3
gotchaThe `skipStartedAction` option (introduced in v1.1.0) changes the behavior of `bindAsyncAction` significantly. When `true`, the `started` action is *not* dispatched automatically but is expected to be manually dispatched as the trigger for the saga, with the saga then dispatching `done`/`failed`. Incorrect usage can lead to missing `started` actions or unexpected saga triggers.
fix
Carefully review the documentation for `skipStartedAction`. If you want automatic `started` action dispatch, do not set this option to `true`. If you use it as a trigger, ensure the `started` action is manually dispatched at the appropriate time.
affects: >=1.1.0
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`.
fix
Ensure `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.
fix
Install `redux-saga` and its type definitions: `npm install redux-saga @types/redux-saga`.
Upgrade
Version history
2.0.0latest on npm
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.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
typescript-fsa-redux-saga — npm install typescript-fsa-redux-saga · libregistry