cartant/ts-action

reducer()/on() don't recognize payload on action

Closed this issue · 3 comments

StackBlitz: https://stackblitz.com/edit/angular-5yot46?file=src%2Fts-action-reducer.ts

image

Inside narrowed reducer, it correctly recognizes State type and only partially recognize Action type.

It sees type property inside but doesn't see a Payload.

Stripping it down to a minimal repro - i.e. just to check for type/compilation errors - this works for me with typescript 2.8.3 and ts-action 6.0.2:

import { action, on, payload } from "ts-action";
const Foo = action("FOO", payload<{ foo: number }>());
on(Foo, (state, action) => { console.log(action.payload.foo); return state; });
on(Foo, (state, { payload }) => { console.log(payload.foo); return state; });

What versions are you using? Note that the README states:

TypeScript version 2.6 or later is required.

Hmm, looks like a problem in Typescript version. I restarted TypeScript language service in IDE, and it picked up recently installed 2.8.3 version and now no errors are shown.

Previously it was typescript 2.5.3.

Probably StackBlitz also uses not the latest version.

No worries.