Skip to content

Commit 62103f5

Browse files
authored
Fix TS7 errors and update TS matrix (#5455)
* Explicitly name destructured options types Works around microsoft/TypeScript#64431 * Update TS matrix to cover 5.x, 6, 7, and "next"
1 parent 71db2d4 commit 62103f5

4 files changed

Lines changed: 65 additions & 109 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 39 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ jobs:
167167

168168
needs: [build]
169169
runs-on: ubuntu-latest
170+
# `next` is a nightly build. A failure there flags an upcoming TypeScript
171+
# change without failing the workflow.
172+
continue-on-error: ${{ matrix.ts == 'next' }}
170173
strategy:
171174
fail-fast: false
172175
matrix:
@@ -213,6 +216,14 @@ jobs:
213216
types: '^19',
214217
react-dom: { version: '^19', types: '^19' },
215218
}
219+
- node: '24.x'
220+
ts: '7.0'
221+
react:
222+
{
223+
version: '^19',
224+
types: '^19',
225+
react-dom: { version: '^19', types: '^19' },
226+
}
216227
- node: '24.x'
217228
ts: 'next'
218229
react:
@@ -221,7 +232,7 @@ jobs:
221232
types: '^19',
222233
react-dom: { version: '^19', types: '^19' },
223234
}
224-
# React 18 × boundary TS versions only (5.6, 6.0, next).
235+
# React 18 × boundary TS versions only (5.6, 6.0, 7.0, next).
225236
# The `@types/*` entries are pinned to exact versions for the same
226237
# reason as in `test-dist` above: `pnpm update -r @types/react@^18`
227238
# resolves to 18.3.12, which lacks the
@@ -244,6 +255,14 @@ jobs:
244255
types: '18.3.31',
245256
react-dom: { version: '^18', types: '18.3.7' },
246257
}
258+
- node: '24.x'
259+
ts: '7.0'
260+
react:
261+
{
262+
version: '^18',
263+
types: '18.3.31',
264+
react-dom: { version: '^18', types: '18.3.7' },
265+
}
247266
- node: '24.x'
248267
ts: 'next'
249268
react:
@@ -294,15 +313,15 @@ jobs:
294313
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
295314

296315
- name: Test types (TS 5.x)
297-
if: matrix.ts != 'next' && !startsWith(matrix.ts, '6.')
316+
if: startsWith(matrix.ts, '5.')
298317
env:
299318
TEST_DIST: true
300319
run: |
301320
pnpm exec tsc --version
302321
pnpm type-tests
303322
304-
- name: Test types (TS 6.x/next)
305-
if: matrix.ts == 'next' || startsWith(matrix.ts, '6.')
323+
- name: Test types (TS 6.x/7.x/next)
324+
if: ${{ !startsWith(matrix.ts, '5.') }}
306325
env:
307326
TEST_DIST: true
308327
run: |
@@ -427,6 +446,9 @@ jobs:
427446
name: 'Test Type Portability: TS ${{ matrix.ts }} + Node ${{ matrix.node }}'
428447
needs: [build]
429448
runs-on: ubuntu-latest
449+
# `next` is a nightly build. A failure there flags an upcoming TypeScript
450+
# change without failing the workflow.
451+
continue-on-error: ${{ matrix.ts == 'next' }}
430452
strategy:
431453
fail-fast: false
432454
matrix:
@@ -448,26 +470,35 @@ jobs:
448470
- node: '24.x'
449471
ts: '6.0'
450472
example: { name: 'bundler', moduleResolution: 'Bundler' }
473+
- node: '24.x'
474+
ts: '7.0'
475+
example: { name: 'bundler', moduleResolution: 'Bundler' }
451476
- node: '24.x'
452477
ts: 'next'
453478
example: { name: 'bundler', moduleResolution: 'Bundler' }
454-
# nodenext-cjs × boundary TS versions only (5.6, 6.0, next)
479+
# nodenext-cjs × boundary TS versions only (5.6, 6.0, 7.0, next)
455480
- node: '24.x'
456481
ts: '5.6'
457482
example: { name: 'nodenext-cjs', moduleResolution: 'NodeNext' }
458483
- node: '24.x'
459484
ts: '6.0'
460485
example: { name: 'nodenext-cjs', moduleResolution: 'NodeNext' }
486+
- node: '24.x'
487+
ts: '7.0'
488+
example: { name: 'nodenext-cjs', moduleResolution: 'NodeNext' }
461489
- node: '24.x'
462490
ts: 'next'
463491
example: { name: 'nodenext-cjs', moduleResolution: 'NodeNext' }
464-
# nodenext-esm × boundary TS versions only (5.6, 6.0, next)
492+
# nodenext-esm × boundary TS versions only (5.6, 6.0, 7.0, next)
465493
- node: '24.x'
466494
ts: '5.6'
467495
example: { name: 'nodenext-esm', moduleResolution: 'NodeNext' }
468496
- node: '24.x'
469497
ts: '6.0'
470498
example: { name: 'nodenext-esm', moduleResolution: 'NodeNext' }
499+
- node: '24.x'
500+
ts: '7.0'
501+
example: { name: 'nodenext-esm', moduleResolution: 'NodeNext' }
471502
- node: '24.x'
472503
ts: 'next'
473504
example: { name: 'nodenext-esm', moduleResolution: 'NodeNext' }
@@ -534,102 +565,16 @@ jobs:
534565
run: rm -rf dist && node_modules/.bin/tsc -p tsconfig.json
535566

536567
- name: Test type portability with `moduleResolution Node10`
537-
if: matrix.ts != 'next' && !startsWith(matrix.ts, '6.')
568+
if: startsWith(matrix.ts, '5.')
538569
working-directory: ./examples/type-portability/${{ matrix.example.name }}
539570
run: rm -rf dist && node_modules/.bin/tsc -p tsconfig.json --module CommonJS --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false
540571

541572
# `npm --workspace=<name> pkg set` needed the root `workspaces` field to
542573
# resolve the name, and that field went away with Yarn. Run inside the
543574
# package directory, `npm pkg set` needs no workspace resolution at all.
544575
- name: Test type portability with `moduleResolution Node10` and `type module` in `package.json`
545-
if: (matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler') && matrix.ts != 'next' && !startsWith(matrix.ts, '6.')
576+
if: (matrix.example.name == 'nodenext-esm' || matrix.example.name == 'bundler') && startsWith(matrix.ts, '5.')
546577
working-directory: ./examples/type-portability/${{ matrix.example.name }}
547578
run: |
548579
npm pkg set type=module
549580
rm -rf dist && node_modules/.bin/tsc -p tsconfig.json --module ESNext --moduleResolution Node10 --preserveSymLinks --verbatimModuleSyntax false
550-
551-
# Advisory only. Reports how RTK's types behave under the next major TypeScript
552-
# release without blocking any PR. `@typescript/native-preview` was the
553-
# pre-release channel for the Go port and is deprecated now that TypeScript 7
554-
# ships from the `typescript` package itself, so this job installs real
555-
# `typescript@7` under an npm alias instead.
556-
test-types-typescript-7:
557-
name: 'Test Types: TypeScript 7 (advisory)'
558-
needs: [build]
559-
runs-on: ubuntu-latest
560-
continue-on-error: true
561-
strategy:
562-
fail-fast: false
563-
matrix:
564-
node: ['24.x']
565-
steps:
566-
- name: Checkout repo
567-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
568-
569-
# Must run before `setup-node`, or `cache: 'pnpm'` cannot locate the store.
570-
- uses: pnpm/setup@84cb39b217b10273981911c288cd62326dc7c6d2 # v2.0.2
571-
with:
572-
install: false
573-
574-
- name: Use node ${{ matrix.node }}
575-
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
576-
with:
577-
node-version: ${{ matrix.node }}
578-
cache: 'pnpm'
579-
580-
- name: Install deps
581-
run: pnpm install
582-
583-
# npm alias, so the repo's own `typescript` devDependency stays on 6.x and
584-
# every other job keeps testing what it tested before.
585-
- name: Install TypeScript 7
586-
run: pnpm add -D typescript-7@npm:typescript@7
587-
588-
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
589-
with:
590-
name: package
591-
path: packages/toolkit
592-
593-
- name: Install build artifact
594-
run: pnpm add ./package.tgz
595-
596-
- name: Show installed RTK versions
597-
run: pnpm list @reduxjs/toolkit
598-
599-
- name: Erase path aliases
600-
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
601-
602-
# Invoked by path rather than through `pnpm exec tsc`. The alias also claims
603-
# the `tsc` bin, so `pnpm exec tsc` happens to resolve to 7 today, but
604-
# depending on that would let this job silently test the wrong compiler.
605-
# `--version` must print 7.x for the run below to mean anything.
606-
- name: Test types with TypeScript 7
607-
env:
608-
TEST_DIST: true
609-
run: |
610-
TSC7="$(ls -d ../../node_modules/typescript-7 node_modules/typescript-7 2>/dev/null | head -1)/bin/tsc"
611-
node "$TSC7" --version
612-
node "$TSC7" -p tsconfig.test.json --noEmit --moduleResolution Bundler
613-
614-
# See the note in `test-type-portability`: without `--ignore-workspace`
615-
# pnpm links `@reduxjs/toolkit` to the workspace sources instead of
616-
# installing the tarball.
617-
- name: Install build artifact for type-portability example
618-
working-directory: ./examples/type-portability/bundler
619-
run: |
620-
npm pkg delete dependencies.@reduxjs/toolkit
621-
pnpm add --ignore-workspace --ignore-scripts --node-linker=hoisted "$GITHUB_WORKSPACE/packages/toolkit/package.tgz"
622-
623-
- name: Install TypeScript 7 for type-portability example
624-
working-directory: ./examples/type-portability/bundler
625-
run: pnpm add --ignore-workspace --ignore-scripts --node-linker=hoisted -D typescript-7@npm:typescript@7
626-
627-
# Invoked by path for a second reason on top of the one above: `pnpm exec`
628-
# runs a dependency-status check that installs with `--frozen-lockfile`,
629-
# and the two steps before this one install with `--ignore-workspace`, so
630-
# the example's `package.json` no longer matches the root lockfile.
631-
- name: Test type portability with TypeScript 7 (bundler example)
632-
working-directory: ./examples/type-portability/bundler
633-
run: |
634-
node node_modules/typescript-7/bin/tsc --version
635-
node node_modules/typescript-7/bin/tsc --noEmit

‎packages/toolkit/src/createSlice.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,10 @@ export function buildCreateSlice({ creators }: BuildCreateSliceConfig = {}) {
809809
caseReducers: context.sliceCaseReducersByName as any,
810810
getInitialState,
811811
...makeSelectorProps(reducerPath),
812-
injectInto(injectable, { reducerPath: pathOpt, ...config } = {}) {
812+
injectInto(
813+
injectable,
814+
{ reducerPath: pathOpt, ...config }: InjectIntoConfig<string> = {},
815+
) {
813816
const newReducerPath = pathOpt ?? reducerPath
814817
injectable.inject({ reducerPath: newReducerPath, reducer }, config)
815818
return {

‎packages/toolkit/src/query/core/buildInitiate.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,22 @@ export type InfiniteQueryActionCreatorResult<
153153
): InfiniteQueryActionCreatorResult<D>
154154
}
155155

156+
type StartMutationActionCreatorOptions = {
157+
/**
158+
* If this mutation should be tracked in the store.
159+
* If you just want to manually trigger this mutation using `dispatch` and don't care about the
160+
* result, state & potential errors being held in store, you can set this to false.
161+
* (defaults to `true`)
162+
*/
163+
track?: boolean
164+
fixedCacheKey?: string
165+
}
166+
156167
type StartMutationActionCreator<
157168
D extends MutationDefinition<any, any, any, any>,
158169
> = (
159170
arg: QueryArgFrom<D>,
160-
options?: {
161-
/**
162-
* If this mutation should be tracked in the store.
163-
* If you just want to manually trigger this mutation using `dispatch` and don't care about the
164-
* result, state & potential errors being held in store, you can set this to false.
165-
* (defaults to `true`)
166-
*/
167-
track?: boolean
168-
fixedCacheKey?: string
169-
},
171+
options?: StartMutationActionCreatorOptions,
170172
) => ThunkAction<MutationActionCreatorResult<D>, any, any, UnknownAction>
171173

172174
export type MutationActionCreatorResult<
@@ -389,7 +391,7 @@ You must add the middleware for RTK-Query to function correctly!`,
389391
subscriptionOptions,
390392
[forceQueryFnSymbol]: forceQueryFn,
391393
...rest
392-
} = {},
394+
}: StartQueryActionCreatorOptions = {},
393395
) =>
394396
(dispatch, getState) => {
395397
const queryCacheKey = serializeQueryArgs({
@@ -545,7 +547,10 @@ You must add the middleware for RTK-Query to function correctly!`,
545547
function buildInitiateMutation(
546548
endpointName: string,
547549
): StartMutationActionCreator<any> {
548-
return (arg, { track = true, fixedCacheKey } = {}) =>
550+
return (
551+
arg,
552+
{ track = true, fixedCacheKey }: StartMutationActionCreatorOptions = {},
553+
) =>
549554
(dispatch, getState) => {
550555
const thunk = mutationThunk({
551556
type: 'mutation',

‎packages/toolkit/src/query/react/buildHooks.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
19531953
refetchOnFocus,
19541954
pollingInterval = 0,
19551955
skipPollingIfUnfocused = false,
1956-
} = {}) => {
1956+
}: SubscriptionOptions = {}) => {
19571957
const { initiate } = api.endpoints[endpointName] as ApiEndpointQuery<
19581958
QueryDefinition<any, any, any, any, any>,
19591959
Definitions
@@ -2213,7 +2213,10 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
22132213
}
22142214

22152215
function buildMutationHook(name: string): UseMutation<any> {
2216-
return ({ selectFromResult, fixedCacheKey } = {}) => {
2216+
return ({
2217+
selectFromResult,
2218+
fixedCacheKey,
2219+
}: UseMutationStateOptions<any, any> = {}) => {
22172220
const { select, initiate } = api.endpoints[name] as ApiEndpointMutation<
22182221
MutationDefinition<any, any, any, any, any>,
22192222
Definitions

0 commit comments

Comments
 (0)