Skip to content

index.d.ts type BoundAction: Expected 0 arguments, but got 1. #129

@reallyely

Description

@reallyely

export type BoundAction = () => void;

I'm looking into use cases for Unistore where I need to expose the store and bound actions for use in other frameworks. I've been taking advantage of store.action() to get a handle on that bound action, but I get typing issues when that action takes parameters due to how BoundAction is defined.

For example when I...

      // define the action as an unary function
      const actions = {
        toggleLoading: (_state: MyState, isLoading: boolean) => ({ isLoading })
      }
      // and then get the bound action from our previously created store
      const toggleLoading = store.action(actions.toggleLoading) 
      // I receive:  TS2554: Expected 0 arguments, but got 1.

I have temporarily sidestepped this issue by locally redefining BoundAction to be:

export type BoundAction = (...args: any) => void;

I'm a TypeScript newbie so I don't have good sensibilities when it comes to typing yet. Is there a 'better' way to type this, or am I doing something wrong?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions