{"id":24319539,"url":"https://github.com/ryym/redux-dutiful-thunk","last_synced_at":"2026-07-13T15:32:13.831Z","repository":{"id":57350594,"uuid":"126434821","full_name":"ryym/redux-dutiful-thunk","owner":"ryym","description":"Typescript friendly redux-thunk","archived":false,"fork":false,"pushed_at":"2019-06-10T12:57:21.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-25T08:58:31.893Z","etag":null,"topics":["redux-thunk","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/redux-dutiful-thunk","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-23T04:54:13.000Z","updated_at":"2019-06-10T12:57:23.000Z","dependencies_parsed_at":"2022-09-15T01:44:21.379Z","dependency_job_id":null,"html_url":"https://github.com/ryym/redux-dutiful-thunk","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ryym/redux-dutiful-thunk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryym%2Fredux-dutiful-thunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryym%2Fredux-dutiful-thunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryym%2Fredux-dutiful-thunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryym%2Fredux-dutiful-thunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryym","download_url":"https://codeload.github.com/ryym/redux-dutiful-thunk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryym%2Fredux-dutiful-thunk/sbom","scorecard":{"id":793283,"data":{"date":"2025-08-11","repo":{"name":"github.com/ryym/redux-dutiful-thunk","commit":"d77cde4edc84c6b7ff9de7f80629e4bfb2843d5c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":4,"reason":"6 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T08:11:41.177Z","repository_id":57350594,"created_at":"2025-08-23T08:11:41.177Z","updated_at":"2025-08-23T08:11:41.177Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35427834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-13T02:00:06.543Z","response_time":119,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["redux-thunk","typescript"],"created_at":"2025-01-17T15:33:41.260Z","updated_at":"2026-07-13T15:32:13.802Z","avatar_url":"https://github.com/ryym.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux Dutiful Thunk\n\n[![npm version](https://img.shields.io/npm/v/redux-dutiful-thunk.svg)](https://www.npmjs.com/package/redux-dutiful-thunk)\n[![circleci](https://circleci.com/gh/ryym/redux-dutiful-thunk.svg?style=svg)](https://circleci.com/gh/ryym/redux-dutiful-thunk)\n\nThis is a [Redux](https://redux.js.org/) middleware almost the same as [redux-thunk](https://github.com/gaearon/redux-thunk), but it respects Redux types.\n\n## Motivation\n\nIn Redux Thunk, you need to pass a thunk function directly to `dispatch` to invoke it.\n\n```js\n// An action creator for Redux Thunk.\nfunction incrementAsync() {\n  return dispatch =\u003e {\n    setTimeout(() =\u003e dispatch(increment()), 1000);\n  };\n}\n\n// Dispatch a function.\nstore.dispatch(incrementAsync());\n```\n\nBut this becomes a problem if you want to write code in a type-safe manner\nbecause the `dispatch` function is supposed to accept Redux actions, not functions.\n\n```js\n// A Redux action consists of a unique `type` and zero or more extra arguments.\n{ type: 'FETCH_USER', id: 30 }\n```\n\nSo for example when you use Redux Thunk with [TypeScript](https://www.typescriptlang.org/),\nyou need to tweak Redux type definitions in some way\n(I don't know about [flow](https://flow.org/) much but I guess a similar problem exists).\nTherefore I could not find a good reason to use a function as a special action.\nInstead, let's create a normal action to meet the Redux rule and match its type definitions.\n\n```js\nimport {thunk} from 'redux-dutiful-thunk';\n\nfunction incrementAsync() {\n  // Wrap your thunk function by `thunk`.\n  return thunk(async dispatch =\u003e {\n      setTimeout(() =\u003e dispatch(increment()), 1000);\n  });\n}\n\n// Now the action creator returns a normal action which contains a function you passed.\nconsole.log(incrementAsync());\n//=\u003e { type: '@@redux-dutiful-thunk/THUNK', thunk: f, }\n\n// So the `dispatch` function can take an action as usual, instead of a function.\nstore.dispatch(incrementAsync());\n```\n\nThe difference with Redux Thunk is only the `thunk` wrapping.\n\n```diff\n function incrementAsync() {\n-  return dispatch =\u003e {\n+  return thunk(async dispatch =\u003e {\n       setTimeout(() =\u003e dispatch(increment()), 1000);\n-  };\n+  });\n }\n```\n\n## Installation\n\n```\nnpm install redux-dutiful-thunk\n```\n\n## Usage\n\nTo enable Redux Dutiful Thunk, create a middleware and apply it to your store.\n\n```js\nimport {createStore, applyMiddleware} from 'redux';\nimport {createThunkMiddleware} from 'redux-dutiful-thunk';\nimport rootReducer from './reducers/index';\n\nconst store = createStore(\n  rootReducer,\n  applyMiddleware(createThunkMiddleware())\n);\n```\n\n### Custom Argument\n\nLike Redux Thunk, you can inject a custom argument to your thunk actions.\n\n```js\nconst store = createStore(\n  rootReducer,\n  applyMiddleware(createThunkMiddleware(api))\n);\n\nfunction fetchUser(id) {\n  return thunk(async (dispatch, getState, api) =\u003e {\n    const user = await api.fetchUser(id);\n    dispatch({type: 'FETCH_USER_SUCCESS', user});\n  });\n}\n```\n\n### With TypeScript\n\nThis library is written in TypeScript so the type definitions are provided.\n\nTo make your `dispatch` function accept any thunk actions,\nadd `AnyThunkAction` to your action type.\n\n```typescript\nimport {AnyThunkAction} from 'redux-dutiful-thunk';\n\ntype Action =\n  | AnyThunkAction\n  | {type: 'FETCH_USER'; id: number}\n  | {type: 'DO_SOMETHING'};\n```\n\nTo implement your thunk action creators easily,\nwe recommend to define a `Thunk` type using `ThunkAction`.\n\n```typescript\nimport {thunk, ThunkAction} from 'redux-dutiful-thunk';\nimport {Action} from './action-type';\nimport {State} from './state';\nimport {API} from './api';\nimport {User} from './models'\n\ntype Thunk\u003cR = void\u003e = ThunkAction\u003cState, Action, API, R\u003e;\n\n// A thunk action creator.\nfunction fetchUser(id: number): Thunk\u003cUser\u003e {\n  // You can omit argument types.\n  return thunk(async (dispatch, getState, api) =\u003e {\n    return await api.fetchUser(id);\n  });\n}\n```\n\n### Thunk's Return Value\n\nBecause the `dispatch` function returns a given value as is,\nyou can get a return value of thunk function in Redux Thunk.\n\n```js\nconst user = await dispatch(fetchUser(id));\nconsole.log('got user', user);\n```\n\nBut this cannot be done in Redux Dutiful Thunk.\n\n```js\n// fetchUser returns an action, not a user data.\nconst action = dispatch(fetchUser(id));\n```\n\nFor this use case, thunk actions have a promise\nthat is resolved to a return value of your thunk function.\n\n```js\nconst action = dispatch(fetchUser(id));\nconst user = await action.promise;\n\n// So you can write like this\nuser = await dispatch(fetchUser(id)).promise;\n```\n\nOf course this promise is type safe.\n\n### Specifying Thunk Type\n\nAll thunk actions have a same action type.\nIf you want to distinguish each thunk action, use `thunkAs` instead of `thunk`.\nThis allows you to specify a thunk type.\n\n```typescript\nimport {thunkAs} from 'redux-dutiful-thunk';\n\nfunction fetchUser(id: number): Thunk\u003cUser\u003e {\n  return thunkAs('FETCH_USER', async (dispatch, getState, api) =\u003e {\n    return await api.fetchUser(id);\n  });\n}\n\nconst action = fetchUser(3);\nconsole.log(action.thunkType === 'FETCH_USER'); //=\u003e true\n```\n\n## API\n\n### Base types\n\n- `Thunk\u003cState, Action, Context, R\u003e`\n\n    ```typescript\n    (dispatch: Dispatch\u003cAction\u003e, getState: () =\u003e State, context: Context) =\u003e R\n    ```\n\n- `ThunkAction\u003cState, Action, Context, R, T\u003e`\n\n    ```typescript\n    {\n      type: string,\n      thunk: Thunk\u003cState, Action, Context, R\u003e,\n      promise: Promise\u003cR\u003e,\n      thunkType: T,\n    }\n    ```\n\n### `thunk`\n\n```typescript\n(f: Thunk\u003cS, A, C, R\u003e) =\u003e ThunkAction\u003cS, A, C, R, null\u003e\n```\n\n### `thunkAs`\n\n```typescript\n(type: T, f: Thunk\u003cS, A, C, R\u003e) =\u003e ThunkAction\u003cS, A, C, R, T\u003e\n```\n\n### `isThunkAction`\n\n```typescript\n(action: AnyAction) =\u003e action is AnyThunkAction\n```\n\n### `createThunkMiddleware`\n\n```typescript\n(contxt?: C) =\u003e Middleware\n```\n\n\nSee [src/index.ts](src/index.ts) for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryym%2Fredux-dutiful-thunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryym%2Fredux-dutiful-thunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryym%2Fredux-dutiful-thunk/lists"}