Skip to content

Commit a98875c

Browse files
authored
Merge pull request #3761 from reduxjs/bugfix/cat-ts-version-compat
2 parents 6f1a4c6 + 083546f commit a98875c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/toolkit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@microsoft/api-extractor": "^7.13.2",
53+
"@phryneas/ts-version": "^1.0.2",
5354
"@size-limit/preset-small-lib": "^4.11.0",
5455
"@testing-library/react": "^13.3.0",
5556
"@testing-library/user-event": "^13.1.5",

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
AsyncThunkFulfilledActionCreator,
2222
AsyncThunkRejectedActionCreator,
2323
} from '@internal/createAsyncThunk'
24+
import type { TSVersion } from '@phryneas/ts-version'
2425

2526
const ANY = {} as any
2627
const defaultDispatch = (() => {}) as ThunkDispatch<{}, any, UnknownAction>
@@ -291,8 +292,22 @@ const unknownAction = { type: 'foo' } as UnknownAction
291292
// in that case, we have to forbid this behaviour or it will make arguments optional everywhere
292293
{
293294
const asyncThunk = createAsyncThunk('test', (arg?: number) => 0)
294-
expectType<(arg?: number) => any>(asyncThunk)
295-
asyncThunk()
295+
296+
// Per https://github.com/reduxjs/redux-toolkit/issues/3758#issuecomment-1742152774 , this is a bug in
297+
// TS 5.1 and 5.2, that is fixed in 5.3. Conditionally run the TS assertion here.
298+
type IsTS51Or52 = TSVersion.Major extends 5
299+
? TSVersion.Minor extends 1 | 2
300+
? true
301+
: false
302+
: false
303+
304+
type expectedType = IsTS51Or52 extends true
305+
? (arg: number) => any
306+
: (arg?: number) => any
307+
expectType<expectedType>(asyncThunk)
308+
// We _should_ be able to call this with no arguments, but we run into that error in 5.1 and 5.2.
309+
// Disabling this for now.
310+
// asyncThunk()
296311
asyncThunk(5)
297312
// @ts-expect-error
298313
asyncThunk('string')

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6808,6 +6808,13 @@ __metadata:
68086808
languageName: node
68096809
linkType: hard
68106810

6811+
"@phryneas/ts-version@npm:^1.0.2":
6812+
version: 1.0.2
6813+
resolution: "@phryneas/ts-version@npm:1.0.2"
6814+
checksum: d51914a8ea35ff8b686a9379b9e9fe6d5b5feaf2e7511b880d2835015736e33bc82952bbc369918f251d4a755f32f4a9c4a34b0ec4dfdbc3e87a41d26401105c
6815+
languageName: node
6816+
linkType: hard
6817+
68116818
"@pmmmwh/react-refresh-webpack-plugin@npm:^0.5.3":
68126819
version: 0.5.7
68136820
resolution: "@pmmmwh/react-refresh-webpack-plugin@npm:0.5.7"
@@ -6981,6 +6988,7 @@ __metadata:
69816988
resolution: "@reduxjs/toolkit@workspace:packages/toolkit"
69826989
dependencies:
69836990
"@microsoft/api-extractor": ^7.13.2
6991+
"@phryneas/ts-version": ^1.0.2
69846992
"@size-limit/preset-small-lib": ^4.11.0
69856993
"@testing-library/react": ^13.3.0
69866994
"@testing-library/user-event": ^13.1.5

0 commit comments

Comments
 (0)