Closed hanayashiki closed 3 years ago
The README.md documentation does not give a correct example for createAction
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.
getTodo
[ ] Are you extending internal types to enable type-free syntax with createReducer?
createReducer
// If yes PASTE HERE your types.d.ts
[x] Did you checked compatibility notes and migration guides?
https://codesandbox.io/s/lucid-ritchie-tg3n0?file=/src/index.ts (PASTE HERE your 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
getTodo can be called with ('some_id', 'some_meta')
('some_id', 'some_meta')
Follow "advanced examples"
{ "compilerOptions": { "strict": true, "module": "commonjs", "jsx": "preserve", "esModuleInterop": true, "sourceMap": true, "allowJs": true, "lib": [ "es6", "dom" ], "rootDir": "src", "moduleResolution": "node" } }
I fixed this issue by switching to redux-toolkit. I suggest all of you do so.
Description
The README.md documentation does not give a correct example for
createAction
For example, the last function does not work with me. TypeScript complains with erorrs that
getTodo
requires 0 params.Mandatory info
[ ] Are you extending internal types to enable type-free syntax with
createReducer
?[x] Did you checked compatibility notes and migration guides?
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.
Expected behavior
getTodo
can be called with('some_id', 'some_meta')
Suggested solution(s)
Follow "advanced examples"
Project Dependencies