redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

isFulfilled() in typescript wouldn't accept spread arguments

Open mark-night opened this issue 4 years ago • 1 comments

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

mark-night avatar Sep 15 '21 07:09 mark-night

Looks like the same issue as #2209

markerikson avatar Jun 29 '22 02:06 markerikson

Merged, will be out in 1.9.2 shortly.

markerikson avatar Jan 28 '23 20:01 markerikson