Skip to content

Commit

Permalink
Merge branch 'middleware-callback' of https://github.com/reduxjs/redu…
Browse files Browse the repository at this point in the history
…x-toolkit into middleware-callback
  • Loading branch information
EskiMojo14 committed Oct 1, 2023
2 parents a72c77f + de56e95 commit d5f916b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion errors.json
Expand Up @@ -29,5 +29,6 @@
"27": "Warning: Middleware for RTK-Query API at reducerPath \"\" has not been added to the store.\n You must add the middleware for RTK-Query to function correctly!",
"28": "Cannot refetch a query that has not been started yet.",
"29": "`builder.addCase` cannot be called with an empty action type",
"30": "`builder.addCase` cannot be called with two reducers for the same action type"
"30": "`builder.addCase` cannot be called with two reducers for the same action type",
"31": "\"middleware\" field must be a callback"
}
1 change: 1 addition & 0 deletions packages/toolkit/package.json
Expand Up @@ -50,6 +50,7 @@
},
"devDependencies": {
"@microsoft/api-extractor": "^7.13.2",
"@phryneas/ts-version": "^1.0.2",
"@size-limit/preset-small-lib": "^4.11.0",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.1.5",
Expand Down
19 changes: 17 additions & 2 deletions packages/toolkit/src/tests/createAsyncThunk.typetest.ts
Expand Up @@ -21,6 +21,7 @@ import type {
AsyncThunkFulfilledActionCreator,
AsyncThunkRejectedActionCreator,
} from '@internal/createAsyncThunk'
import type { TSVersion } from '@phryneas/ts-version'

const ANY = {} as any
const defaultDispatch = (() => {}) as ThunkDispatch<{}, any, UnknownAction>
Expand Down Expand Up @@ -291,8 +292,22 @@ const unknownAction = { type: 'foo' } as UnknownAction
// in that case, we have to forbid this behaviour or it will make arguments optional everywhere
{
const asyncThunk = createAsyncThunk('test', (arg?: number) => 0)
expectType<(arg?: number) => any>(asyncThunk)
asyncThunk()

// Per https://github.com/reduxjs/redux-toolkit/issues/3758#issuecomment-1742152774 , this is a bug in
// TS 5.1 and 5.2, that is fixed in 5.3. Conditionally run the TS assertion here.
type IsTS51Or52 = TSVersion.Major extends 5
? TSVersion.Minor extends 1 | 2
? true
: false
: false

type expectedType = IsTS51Or52 extends true
? (arg: number) => any
: (arg?: number) => any
expectType<expectedType>(asyncThunk)
// We _should_ be able to call this with no arguments, but we run into that error in 5.1 and 5.2.
// Disabling this for now.
// asyncThunk()
asyncThunk(5)
// @ts-expect-error
asyncThunk('string')
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Expand Up @@ -6808,6 +6808,13 @@ __metadata:
languageName: node
linkType: hard

"@phryneas/ts-version@npm:^1.0.2":
version: 1.0.2
resolution: "@phryneas/ts-version@npm:1.0.2"
checksum: d51914a8ea35ff8b686a9379b9e9fe6d5b5feaf2e7511b880d2835015736e33bc82952bbc369918f251d4a755f32f4a9c4a34b0ec4dfdbc3e87a41d26401105c
languageName: node
linkType: hard

"@pmmmwh/react-refresh-webpack-plugin@npm:^0.5.3":
version: 0.5.7
resolution: "@pmmmwh/react-refresh-webpack-plugin@npm:0.5.7"
Expand Down Expand Up @@ -6981,6 +6988,7 @@ __metadata:
resolution: "@reduxjs/toolkit@workspace:packages/toolkit"
dependencies:
"@microsoft/api-extractor": ^7.13.2
"@phryneas/ts-version": ^1.0.2
"@size-limit/preset-small-lib": ^4.11.0
"@testing-library/react": ^13.3.0
"@testing-library/user-event": ^13.1.5
Expand Down

0 comments on commit d5f916b

Please sign in to comment.