Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'State' does not satisfy the constraint '(state: any, ...args: any[]) => any'

It is probably a noobish question, but how do I deal with the Typescript error TS2344?

Type 'State' does not satisfy the constraint '(state: any, ...args: any[]) => any'.

Here is the code fragement of my sagas.ts where the error occurs

function* loadPageFull(action: Actions.LoadPageFullAction ) {
    if (!action.id)
        return;
    const currentPageFull: Interfaces.PageFull = 
      yield (select<Top.State>(Selectors.getPageFull(action.id))); // <-- error occurs here

    if (!currentPageFull || action.forceReload) {
        // here we query the API of the backend and return some JSON
    }
}

The problem seems to be the Top.State in the line with the yield. The curious thing is that I did not have the error before updating Typescript to version 3.6.4.

EDIT: The getPageFull is defined in selectors.ts as

const getPageFullInner = (state: State, id: number) => state.pagesFull.get(id);
export const getPageFull = (id: number) => (state: Top.State) 
    => getPageFullInner(foobar(state), id);

The foobar() function is also defined there

export const foobar = (state: State) => state.foobar;

References

  • How to go about understanding the type ...args: any[]) => any
  • https://redux-saga.js.org/docs/api/#selectselector-args
like image 957
B--rian Avatar asked Dec 02 '25 00:12

B--rian


1 Answers

The signature of select is:

export function select<Fn extends (state: any, ...args: any[]) => any>(
  selector: Fn,
  ...args: Tail<Parameters<Fn>>
): SelectEffect

So the first generic parameter has to be a function type (specifically (state: any, ...args: any[]) => any), but you're giving it State.

You don't need to specify the generic parameter, as it can be inferred from the argument, so you can simply write:

select(Selectors.getPageFull(action.id))
like image 179
emlai Avatar answered Dec 04 '25 15:12

emlai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!