{"id":12234,"library":"typescript-fsa-redux-saga","title":"TypeScript FSA utilities for redux-saga","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/aikoven/typescript-fsa-redux-saga","tags":["javascript","redux-saga","typescript","action","action creator"],"install":[{"cmd":"npm install typescript-fsa-redux-saga","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-fsa-redux-saga","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-fsa-redux-saga","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for creating FSA-compliant, type-safe action creators, which this package extends.","package":"typescript-fsa","optional":false},{"reason":"The core library for managing side effects, which this package integrates with.","package":"redux-saga","optional":false}],"imports":[{"note":"This is the primary named export for the library's core functionality.","wrong":"import bindAsyncAction from 'typescript-fsa-redux-saga';","symbol":"bindAsyncAction","correct":"import { bindAsyncAction } from 'typescript-fsa-redux-saga';"},{"note":"Essential for creating async action creators used by `bindAsyncAction`. It is a default export from the `typescript-fsa` library.","wrong":"import { actionCreatorFactory } from 'typescript-fsa';","symbol":"actionCreatorFactory","correct":"import actionCreatorFactory from 'typescript-fsa';"},{"note":"The primary return type for Redux Saga generators, commonly used when defining worker sagas wrapped by `bindAsyncAction`.","wrong":"import SagaIterator from 'redux-saga';","symbol":"SagaIterator","correct":"import { SagaIterator } from 'redux-saga';"}],"quickstart":{"code":"import actionCreatorFactory from 'typescript-fsa';\nimport { SagaIterator } from 'redux-saga';\nimport { call } from 'redux-saga/effects';\nimport { bindAsyncAction } from 'typescript-fsa-redux-saga';\n\n// actions.ts (excerpt)\nconst actionCreator = actionCreatorFactory('MY_APP');\n\nexport const doSomething =\n  actionCreator.async<{foo: string},   // parameter type\n                      {bar: number}    // result type\n                     >('DO_SOMETHING');\n\n// A mock API call function\nasync function fetchSomething(param: string): Promise<number> {\n  console.log(`Simulating API call with: ${param}`);\n  return new Promise(resolve => setTimeout(() => resolve(param.length * 10), 500));\n}\n\n// The worker saga wrapped by bindAsyncAction\nconst doSomethingWorker = bindAsyncAction(doSomething)(\n  function* (params): SagaIterator<{bar: number}> {\n    // `params` type is `{foo: string}`\n    console.log(`Worker saga started with params:`, params);\n    const result = yield call(fetchSomething, params.foo);\n    console.log(`API call returned:`, result);\n    return {bar: result};\n  },\n);\n\n// A root saga that demonstrates calling the async worker\nfunction* myRootSaga(): SagaIterator {\n  console.log('Initiating doSomething action...');\n  // Calling the worker directly. bindAsyncAction internally dispatches\n  // doSomething.started, doSomething.done (or doSomething.failed if an error occurs).\n  const result = yield call(doSomethingWorker, {foo: 'example_data'});\n  console.log('doSomethingWorker completed with result:', result);\n\n  try {\n    console.log('Initiating another doSomething action (simulating potential error path)...');\n    yield call(doSomethingWorker, {foo: 'error_case'}); // For demo, assuming this could lead to error\n  } catch (e) {\n    console.error('Caught an error in saga outside worker:', e); // Errors from worker are re-thrown by bindAsyncAction\n  }\n}\n\n// To run this in a Redux Saga setup, you would typically pass `myRootSaga` to `sagaMiddleware.run`.\n// Example (for conceptual understanding, not directly executable without Redux setup):\n// import createSagaMiddleware from 'redux-saga';\n// import { createStore, applyMiddleware } from 'redux';\n// const sagaMiddleware = createSagaMiddleware();\n// const store = createStore(() => ({}), applyMiddleware(sagaMiddleware));\n// sagaMiddleware.run(myRootSaga);\n","lang":"typescript","description":"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."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Prior 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.","severity":"gotcha","affected_versions":">=1.0.3"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `typescript-fsa` is installed at version `^3.0.0` or later (`npm install typescript-fsa@^3`).","cause":"Mismatched major versions between `typescript-fsa-redux-saga` and `typescript-fsa`. `typescript-fsa-redux-saga@2.x` requires `typescript-fsa@3.x`.","error":"TypeError: (0 , typescript_fsa_1.actionCreatorFactory) is not a function"},{"fix":"Install `redux-saga` and its type definitions: `npm install redux-saga @types/redux-saga`.","cause":"`redux-saga` or its type definitions (`@types/redux-saga`) are not installed, or there's a version mismatch.","error":"Error: Could not find type definition for 'redux-saga'"}],"ecosystem":"npm"}