Skip to content

isFulfilled() in typescript wouldn't accept spread arguments #1511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mark-night opened this issue Sep 15, 2021 · 2 comments
Closed

isFulfilled() in typescript wouldn't accept spread arguments #1511

mark-night opened this issue Sep 15, 2021 · 2 comments

Comments

@mark-night
Copy link

const someSlice = createSlice({
  /* ... */
  extraReducers: builder => {
    builder.addMatcher(
      isFulfilled(...someAsyncThunkArray), // <-- A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556)
      someReducer
    );
  }
});

Is this intended behavior? Inline document says the param (asyncThunks) is optional. New to typescript, but it looks like the type definition defined asyncThunks as a tuple?

export declare function isFulfilled<AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]>(...asyncThunks: >AsyncThunks): (action: any) => action is FulfilledActionFromAsyncThunk<AsyncThunks[number]>;

I tried isFulfilled(someAsyncThunkArray[0], ...someAsyncThunkArray.slice(1)) which at least doesn't yell at me, but not sure if it's the correct way to do it. (someAsyncThunkArray has at least 2 items in my case)

Any suggestions?

@reduxjs/toolkit v1.6.1
typescript v4.4.3

@markerikson
Copy link
Collaborator

Looks like the same issue as #2209

@markerikson
Copy link
Collaborator

Merged, will be out in 1.9.2 shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants