Closed arx-8 closed 4 years ago
Is this repository dead? :sob:
Hi @arx-8 ! This repository is not dead! I'm just very sorry to say I didn't see your first report in August. I am looking into it now.
It looks like this has been broken since 2.6, where changes were made to checking function covariance (see the release notes), which is quite a long time so I suppose not many people are using this method.
I'll take a look at fixing it.
Hi again @arx-8 ! Actually, I think things might be working fine. Your repro sees an error because the handler in .cases
doesn't return a state. If I modify your sample code to add the line return state
, e.g.
const reducer2 = reducerWithInitialState(INITIAL_STATE).cases(
[setName, addBalance],
(state, payload) => {
// Payload has type SetNamePayload | AddBalancePayload.
// ...
console.log(state)
console.log(payload)
return state
}
)
Then it correctly typechecks and payload
is correctly inferred as string | number
.
I agree that TypeScript's error message in this case was particularly unhelpful. I'll update the README to show a return value in the .cases
example.
@dphilipson Sorry for my late reply.
I am very sorry that return state
is the basic knowledge of Redux. :bowing_man:
And I tried again.
It is working correctly with TypeScript 3.7!
error-reproduction(fixed).zip
Thank you for your kind response & Update README!
Thank you for creating an awesome package!
I tried to Usage code, however I got a following error message.
Could you tell me how to fix this error?
Error message
Reproducible code
error-reproduction.zip
Reporter's environment
Expect result
tsc
pass with no error.