Skip to content

Commit 17befa6

Browse files
phryneasmarkerikson
authored andcommitted
add another type test documenting still incomplete behaviour
1 parent 8e82f4e commit 17befa6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/toolkit/src/tests/createAsyncThunk.typetest.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,29 @@ const anyAction = { type: 'foo' } as AnyAction
623623
return test1 + test2
624624
})
625625

626+
const thunk3 = typedCAT<
627+
number,
628+
string,
629+
// @ts-expect-error TODO
630+
// right now this still errors because
631+
// it does not contain `state` and `dispatch`
632+
{
633+
rejectValue: string
634+
}
635+
>('foo', (arg, api) => {
636+
// correct getState Type
637+
const test1: number = api.getState().foo.value
638+
// correct dispatch type
639+
const test2: number = api.dispatch(
640+
(dispatch, getState) => getState().foo.value
641+
)
642+
if (1 < 2) {
643+
// TODO: @ts-expect-error
644+
return api.rejectWithValue(5)
645+
}
646+
return api.rejectWithValue(5)
647+
})
648+
626649
const slice = createSlice({
627650
name: 'foo',
628651
initialState: { value: 0 },
@@ -635,6 +658,10 @@ const anyAction = { type: 'foo' } as AnyAction
635658
.addCase(thunk2.fulfilled, (state, action) => {
636659
state.value += action.payload
637660
})
661+
.addCase(thunk3.rejected, (state, action) => {
662+
// @ts-expect-error TODO does not have the right type yet because the config was incomplete
663+
state.value += action.payload
664+
})
638665
},
639666
})
640667

0 commit comments

Comments
 (0)