Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typesafe-actions

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typesafe-actions

Typesafe Action Creators for Redux / Flux Architectures (in TypeScript)

  • 5.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is typesafe-actions?

The typesafe-actions npm package is a utility library for creating and handling Redux actions in a type-safe manner. It helps developers to avoid common pitfalls with TypeScript and Redux by providing a set of tools to create actions, reducers, and epics with strong type safety.

What are typesafe-actions's main functionalities?

Action Creators

Action creators are functions that return action objects. The `createAction` function from typesafe-actions allows you to create these action creators with type safety. The first example creates an action creator for an 'INCREMENT' action with no payload, while the second example creates an action creator for an 'ADD' action that takes a number as its payload.

const increment = createAction('INCREMENT')();
const add = createAction('ADD')<number>();

Reducers

Reducers are functions that determine how the state changes in response to actions. The `createReducer` function from typesafe-actions allows you to create reducers with type safety. The example shows a reducer for a counter that handles 'INCREMENT' and 'ADD' actions.

const counter = createReducer(0)
  .handleAction(increment, state => state + 1)
  .handleAction(add, (state, action) => state + action.payload);

Epics

Epics are functions that handle side effects in Redux applications. The `isActionOf` function from typesafe-actions helps to filter actions in a type-safe manner. The example shows an epic that listens for 'INCREMENT' actions and dispatches an 'ADD' action with a payload of 1.

const incrementEpic: Epic = action$ => action$.pipe(
  filter(isActionOf(increment)),
  map(() => add(1))
);

Other packages similar to typesafe-actions

Keywords

FAQs

Package last updated on 02 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc