Closed piotrwitek closed 5 years ago
I think it might be related to #42, I'm planning to investigate it this week.
Hi, I just noticed the same problem that was mentioned in https://github.com/piotrwitek/typesafe-actions/issues/43#issuecomment-391305184.
Specifically, a "default" typescript configuration created via tsconfig --init
sets strict: true
, which means that strictFunctionTypes
is enabled by default. So it's unforunate that the .map()
example in the README doesn't work with it.
Here's a full example that fails to compile, which depends only on typesafe-actions
(no need for redux
, react-redux
, etc):
import { createStandardAction } from 'typesafe-actions';
const ADD = '@prefix/ADD';
interface Todo {
title: string;
id: string;
completed: boolean;
}
function cuid(): string {
return 'this is a fake value';
}
// Below is literally what's in README.md.
export const add = createStandardAction(ADD).map(
({ title }: { title: string }) => ({
payload: { title, id: cuid(), completed: false } as Todo,
})
);
This is the error output by tsc
:
error TS2345: Argument of type '({ title }: { title: string; }) => { payload: Todo; }' is not assignable to parameter of type '(payload?: { title: string; } | undefined, meta?: void | undefined) => { payload: Todo; }'.
Types of parameters '__0' and 'payload' are incompatible.
Type '{ title: string; } | undefined' is not assignable to type '{ title: string; }'.
Type 'undefined' is not assignable to type '{ title: string; }'.
Anyways, for now I am just using createAction
for such use cases instead of createStandardAction
, e.g. rewriting the above as:
export const add = createAction(ADD, resolve => {
return ({ title }: { title: string }) => resolve({
title,
id: cuid(),
completed: false
} as Todo);
});
Regardless, thanks again for making this library, I think it will make my redux life much easier!
@boostio funded this issue with $10. Visit this issue on Issuehunt
@loadbalance-sudachi-kun funded this issue with $256. Visit this issue on Issuehunt
@piotrwitek has started working. Visit this issue on Issuehunt
@piotrwitek has submitted a pull request. See it on IssueHunt
@piotrwitek has rewarded $186.20 to @piotrwitek. See it on IssueHunt
investigate an issue mentioned here: https://github.com/piotrwitek/typesafe-actions/issues/43#issuecomment-391305184