question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v3.2.1 type error: An argument for 'payload' was not provided.

See original GitHub issue

i have a storeAction that does not receive a payload.

but i can’t call that now without an argument:

 const increaseBenefitsNavCounter = useStoreActions(
    (s) => s.navigation.increaseBenefitsNavCounter,
  );

 // later
increaseBenefitsNavCounter(); // <<--- type error

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
macrozonecommented, Nov 6, 2019

oops, i found the problem. In this project we have very simple local state, so i did not notice it:

we derived typeof’d part of the state, personally I prefer to not repeat literals 😉

This looks like this:

interface State {
  mobileNavVisible: boolean;
  benefitsNavCounter: number;
}
const initialState = {
  mobileNavVisible: false,
  benefitsNavCounter: 0,
};
export default {
  ...initialState,
  showMobileNav: action((state: State) => {
    state.mobileNavVisible = true;
  }),
  hideMobileNav: action((state: State) => {
    state.mobileNavVisible = false;
  }),
  toggleMobileNav: action((state: State) => {
    state.mobileNavVisible = !state.mobileNavVisible;
  }),
  increaseBenefitsNavCounter: action((state: State) => {
    state.benefitsNavCounter++;
  }),
  closeBenefitsNav: action((state: State) => {
    state.benefitsNavCounter = 5;
  }),
};

// in the global model:

import { Actions, createTypedHooks, Dispatch, Meta, State, Thunk } from "easy-peasy";

import cart from "../modules/cart/model";
import checkout from "../modules/checkout/model";

import navigation from "../modules/navigation/model"; // <-- this is the one from above
import profile from "../modules/profile/model";
import { Injections } from "./initStore";

const model = {
  cart,
  checkout,
  profile,
  navigation,
};

export type AppStore = typeof model;
export type AppState = State<AppStore>;
export type AppActions = Actions<AppStore>;
export type AppDispatch = Dispatch<AppStore>;

export type AppThunk<Model extends {}, Payload = void, Result = any> = Thunk<
  Model,
  Payload,
  Injections,
  AppStore,
  Promise<Result>
>;

export interface AppThunkHelpers<Model extends {}> {
  dispatch: Dispatch<AppStore>;
  getState: () => State<Model>;
  getStoreActions: () => Actions<AppStore>;
  getStoreState: () => State<AppStore>;
  injections: Injections;
  meta: Meta;
}

const { useStoreActions, useStoreState, useStoreDispatch } = createTypedHooks<AppStore>();
export { useStoreActions, useStoreState, useStoreDispatch };

export default model;

I now change slightly, which is clearer:

 increaseBenefitsNavCounter: action<State>((state) => {
    state.benefitsNavCounter++;
  }),

now typechecks work properly!

0reactions
ctrlplusbcommented, Nov 6, 2019

I just testing this in 3.6.4 and 3.7.2 and couldn’t reproduce the error.

Did you restart you TS server?

Read more comments on GitHub >

github_iconTop Results From Across the Web

An argument for 'payload' was not provided. error in ...
I get the following if i replace that line: (1)Cannot find name 'payload'. (2) Property 'subscribe' does not exist on type 'void'. –...
Read more >
An argument for 'X' was not provided in TypeScript | bobbyhadz
The error "An argument for 'X' was not provided" occurs when we don't provide a value for a required parameter when calling a...
Read more >
Error A case reducer on a non-draftable value must not return ...
I'm trying to import typescript in my redux application. I use redux toolkit createSlice function like this:
Read more >
Quickstart — Requests 2.28.1 documentation
Quickstart¶. Eager to get started? This page gives a good introduction in how to get started with Requests. First, make sure that: Requests...
Read more >
GraphQL specification
Finally, oftentimes it is useful to provide complex structs as inputs to GraphQL field arguments or variables; the Input Object type allows the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found