# Aurelia Store, immerjs and TypeScript

**URL:** <https://discourse.aurelia.io/t/aurelia-store-immerjs-and-typescript/2599>\
**Category:** Help Requests\
**Created:** [May 31, 2019, 3:06pm UTC](https://discourse.aurelia.io/t/aurelia-store-immerjs-and-typescript/2599 "2019-05-31T15:06:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jenselme](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/jenselme/32/39_2.png) [@Jenselme](https://discourse.aurelia.io/u/Jenselme)\
**Post date:** [May 31, 2019, 3:06pm UTC](https://discourse.aurelia.io/t/aurelia-store-immerjs-and-typescript/2599/1 "2019-05-31T15:06:33Z")

</div>

In a demo app, I am integration Aurelia Store. Since [immerjs](https://github.com/immerjs/immer) looks like a nice addition to ease state management (mostly to avoid spread operator everywhere), I decided to give it a try.

Following [this example](https://github.com/zewa666/aurelia-store-examples/blob/master/immer/src/app.ts), I modified my action into:

```auto
function logout(state) {
    return produce(state, (draft: IState) => {
        draft.authentication = null;
    });
}

```

But I get this error from the TS compiler:

```auto
 TS2345: Argument of type '(state: any) => <Base extends (draft: IState) => void>(base?: Base, ...rest: unknown[]) => any' is not assignable to parameter of type 'Reducer<IState, any[]>'.
  Type '<Base extends (draft: IState) => void>(base?: Base, ...rest: unknown[]) => any' is not assignable to type 'false | IState | Promise<false | IState>'.
    Type '<Base extends (draft: IState) => void>(base?: Base, ...rest: unknown[]) => any' is missing the following properties from type 'Promise<false | IState>': then, catch, [Symbol.toStringTag]

```

I managed to work around this by using [immerjs currying](https://github.com/immerjs/immer#currying):

```auto
const logout = produce((draft: IState) => {
        draft.authentication = null;
        performRouterNavigation(draft, 'login');
    });

```

Any idea where this comes from and how to get rid of it while using functions like in the example? It’s not a big deal since there is a work around (which is readable and a little more compact but you can’t use `logout.name` to give your action a name), but I still want to know an answer 😉 (and I think, since the example does it this way, others will encounter this issue).

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [May 31, 2019, 3:37pm UTC](https://discourse.aurelia.io/t/aurelia-store-immerjs-and-typescript/2599/2 "2019-05-31T15:37:33Z")

</div>

In the function signature logout above you havent defined the type of state, I guess thats part of the problem since the produce call cant properly resolve its first argument.

---

<div class="post-metadata">

**Author:** ![Jenselme](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/jenselme/32/39_2.png) [@Jenselme](https://discourse.aurelia.io/u/Jenselme)\
**Post date:** [May 31, 2019, 3:59pm UTC](https://discourse.aurelia.io/t/aurelia-store-immerjs-and-typescript/2599/3 "2019-05-31T15:59:23Z")

</div>

> [@Jenselme](#):
>
> function logout(state) { return produce(state, (draft: IState) =\> { draft.authentication = null; }); }

That was it, thanks.
