piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 99 forks source link

Wrong Documentation #249

Closed hanayashiki closed 3 years ago

hanayashiki commented 3 years ago

Description

The README.md documentation does not give a correct example for createAction

import { createAction } from 'typesafe-actions';

// - with type only
const increment = createAction('INCREMENT');
dispatch(increment());
// { type: 'INCREMENT' };

// - with type and payload
const add = createAction('ADD', action => {
  return (amount: number) => action(amount);
});
dispatch(add(10));
// { type: 'ADD', payload: number }

// - with type and meta
const getTodos = createAction('GET_TODOS', action => {
  return (params: Params) => action(undefined, params);
});
dispatch(getTodos('some_meta'));
// { type: 'GET_TODOS', meta: Params }

// - and finally with type, payload and meta
const getTodo = createAction('GET_TODO', action => {
  return (id: string, meta: string) => action(id, meta);
});
dispatch(getTodo('some_id', 'some_meta'));
// { type: 'GET_TODO', payload: string, meta: string }

For example, the last function does not work with me. TypeScript complains with erorrs that getTodo requires 0 params. image

Mandatory info

How to Reproduce

CodeSandbox Link

https://codesandbox.io/s/lucid-ritchie-tg3n0?file=/src/index.ts (PASTE HERE your codesandbox link)

No CodeSandbox Link

If no codesandbox, then please provide a full working code example below including actions, reducers and your custom types used in the example.

// PASTE HERE your full working code example 

Expected behavior

getTodo can be called with ('some_id', 'some_meta')

Suggested solution(s)

Follow "advanced examples"

Project Dependencies

hanayashiki commented 3 years ago

I fixed this issue by switching to redux-toolkit. I suggest all of you do so.