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 98 forks source link

property payload does not exist on action generated by action-enhancer #154

Closed maheffa closed 5 years ago

maheffa commented 5 years ago

Description

The field payload cannot be accessed in the reducer, even if the action is generated using the enhancer, or the createStandardAction utility. This is also the case for the current version of the code on codesandbox

///features/todos/reducer.ts:20 image

Steps to Reproduce

simple-action-reducer.ts

import { createAction, createReducer } from 'typesafe-actions';

export const add = createAction('todos/ADD', action => {
  return (title: string) => action({ id: 24, title, completed: false });
});

const counterReducer = createReducer([])
  .handleAction(add, (state, action) => state.concat(action.payload));
~$ tsc simple-action-reducer.ts

simple-action-reducer.ts:8:56 - error TS2339: Property 'payload' does not exist on type '{}'.

8   .handleAction(add, (state, action) => state + action.payload);

Expected behavior

payload field should be recognized by the compiler.

Project Dependencies

piotrwitek commented 5 years ago

Hey @maheffa, I think you have missed this section: https://github.com/piotrwitek/typesafe-actions#extending-internal-types-to-enable-type-free-syntax-with-createreducer

I have updated API docs to be clearer about createReducer API and linked to the relevant tutorial section.

PS: codesandbox is not supporting all TS features and it's using v3.3, best to use your local env to reproduce type issues

Kenpa commented 5 years ago

Hey @piotrwitek, I am also facing this issue on v4.4.0 and typescript 3.4.5.

The current sandbox version is suffering the same issue as well (i cloned the project and ran it in my local env):

Capture d’écran 2019-06-24 à 01 17 29
piotrwitek commented 5 years ago

Hey @Kenpa I have just checked a clean installation of codesandbox in the recent master and there is no such issue. Please doublecheck on recent please.

Kenpa commented 5 years ago

My bad, misread my typescript version, was running an old one... Sorry for that

piotrwitek commented 5 years ago

No biggie 😉

On Mon, Jun 24, 2019, 11:43 PM Tchi-An Jean PHOU notifications@github.com wrote:

My bad, misread my typescript version, was running an old one... Sorry for that

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/piotrwitek/typesafe-actions/issues/154?email_source=notifications&email_token=AAFUOA3UM2BPXMV7D3ILLPLP4E5Y3A5CNFSM4HNZDBO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYOKICQ#issuecomment-505193482, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFUOAYZXOFBHHVD2IXGDGTP4E5Y3ANCNFSM4HNZDBOQ .