Skip to content

Commit 0c6b55e

Browse files
committed
Fix @typescript-eslint/no-unused-expressions related issues
1 parent 42635f5 commit 0c6b55e

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

packages/toolkit/src/immutableStateInvariantMiddleware.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Middleware } from 'redux'
22
import type { IgnorePaths } from './serializableStateInvariantMiddleware'
3+
import type { AnyObject } from './tsHelpers'
34
import { getTimeMeasureUtils } from './utils'
45

56
type EntryProcessor = (key: string, value: any) => any
@@ -190,8 +191,16 @@ export function createImmutableStateInvariantMiddleware(
190191
return function (this: any, key: string, value: any) {
191192
if (stack.length > 0) {
192193
const thisPos = stack.indexOf(this)
193-
~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
194-
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
194+
if (~thisPos) {
195+
stack.splice(thisPos + 1)
196+
} else {
197+
stack.push(this)
198+
}
199+
if (~thisPos) {
200+
keys.splice(thisPos, Infinity, key)
201+
} else {
202+
keys.push(key)
203+
}
195204
if (~stack.indexOf(value)) value = decycler!.call(this, key, value)
196205
} else stack.push(value)
197206

packages/toolkit/src/query/tests/cacheCollection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ test(`query: handles large keepUnuseDataFor values over 32-bit ms`, async () =>
8787
expect(onCleanup).not.toHaveBeenCalled()
8888

8989
// _Should_ be called _wayyyy_ in the future (like 24.8 days from now)
90-
vi.advanceTimersByTime(THIRTY_TWO_BIT_MAX_TIMER_SECONDS * 1000),
91-
expect(onCleanup).toHaveBeenCalled()
90+
vi.advanceTimersByTime(THIRTY_TWO_BIT_MAX_TIMER_SECONDS * 1000)
91+
expect(onCleanup).toHaveBeenCalled()
9292
})
9393

9494
describe(`query: await cleanup, keepUnusedDataFor set`, () => {

packages/toolkit/src/query/tests/cleanup.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// tests for "cleanup-after-unsubscribe" behavior
2-
import React from 'react'
32

43
import { createListenerMiddleware } from '@reduxjs/toolkit'
54
import { QueryStatus, createApi } from '@reduxjs/toolkit/query/react'
65
import { act, render, screen, waitFor } from '@testing-library/react'
6+
import type { ReactNode } from 'react'
77
import { setupApiStore } from '../../tests/utils/helpers'
88
import type { SubscriptionSelectors } from '../core/buildMiddleware/types'
99

@@ -24,7 +24,7 @@ const getSubStateA = () => storeRef.store.getState().api.queries['a(undefined)']
2424
const getSubStateB = () => storeRef.store.getState().api.queries['b(undefined)']
2525

2626
function UsingA() {
27-
const { data } = api.endpoints.a.useQuery()
27+
const { data } = api.endpoints.a.useQuery() as { data: ReactNode }
2828

2929
return <>Result: {data} </>
3030
}

packages/toolkit/src/query/tests/retry.test-d.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { retry, type RetryOptions } from '@internal/query/retry'
2-
import {
3-
fetchBaseQuery,
4-
type FetchBaseQueryError,
5-
type FetchBaseQueryMeta,
6-
} from '@internal/query/fetchBaseQuery'
1+
import type { AnyObject } from '@internal/tsHelpers'
2+
import type {
3+
FetchBaseQueryError,
4+
FetchBaseQueryMeta,
5+
RetryOptions,
6+
} from '@reduxjs/toolkit/query'
7+
import { fetchBaseQuery, retry } from '@reduxjs/toolkit/query'
78

89
describe('type tests', () => {
910
test('RetryOptions only accepts one of maxRetries or retryCondition', () => {
@@ -20,8 +21,8 @@ describe('type tests', () => {
2021
}).not.toMatchTypeOf<RetryOptions>()
2122
})
2223
test('fail can be pretyped to only accept correct error and meta', () => {
23-
expectTypeOf(retry.fail).parameter(0).toEqualTypeOf<unknown>()
24-
expectTypeOf(retry.fail).parameter(1).toEqualTypeOf<{} | undefined>()
24+
expectTypeOf(retry.fail).parameter(0).toBeUnknown()
25+
expectTypeOf(retry.fail).parameter(1).toEqualTypeOf<AnyObject | undefined>()
2526
expectTypeOf(retry.fail).toBeCallableWith('Literally anything', {})
2627

2728
const myBaseQuery = fetchBaseQuery()
@@ -40,7 +41,7 @@ describe('type tests', () => {
4041
{ request: new Request('http://localhost') },
4142
)
4243

43-
expectTypeOf(typedFail).parameter(0).not.toMatchTypeOf<string>()
44-
expectTypeOf(typedFail).parameter(1).not.toMatchTypeOf<{}>()
44+
expectTypeOf(typedFail).parameter(0).not.toBeString()
45+
expectTypeOf(typedFail).parameter(1).not.toMatchTypeOf<AnyObject>()
4546
})
4647
})

packages/toolkit/src/tests/createDraftSafeSelector.withTypes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ describe(createDraftSafeSelector.withTypes, () => {
4444
(todos) => todos.map(({ id }) => id),
4545
)
4646

47-
expect(selectTodoIds(rootState)).to.be.an('array').that.is.not.empty
47+
expect(selectTodoIds(rootState)).to.be.an('array').with.lengthOf(2)
4848
})
4949
})

0 commit comments

Comments
 (0)