Skip to content

Commit a596a5a

Browse files
committed
Fix no-constant-condition related problems
1 parent affc5e8 commit a596a5a

File tree

5 files changed

+13
-44
lines changed

5 files changed

+13
-44
lines changed

packages/toolkit/src/listenerMiddleware/tests/useCases.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('Saga-style Effects Scenarios', () => {
122122
const pollingTask = listenerApi.fork(async (forkApi) => {
123123
pollingTaskStarted = true
124124
try {
125-
while (true) {
125+
while (pollingTaskStarted) {
126126
// Cancelation-aware pause for a new server message
127127
const serverEvent = await forkApi.pause(pollForEvent())
128128
// Process the message. In this case, just count the times we've seen this message.

packages/toolkit/src/query/retry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const retryWithBackoff: BaseQueryEnhancer<
142142
}
143143
let retry = 0
144144

145+
// eslint-disable-next-line no-constant-condition
145146
while (true) {
146147
// Check if aborted before each attempt
147148
failIfAborted(api.signal)

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
createApi,
2222
fetchBaseQuery,
2323
} from '@reduxjs/toolkit/query'
24-
import { HttpResponse, delay, http } from 'msw'
24+
import { delay, http, HttpResponse } from 'msw'
2525
import nodeFetch from 'node-fetch'
2626
import * as v from 'valibot'
2727
import type { SchemaFailureHandler } from '../endpointDefinitions'
@@ -420,21 +420,6 @@ describe('endpoint definition typings', () => {
420420
const storeRef = setupApiStore(api, undefined, {
421421
withoutTestLifecycles: true,
422422
})
423-
// only type-test this part
424-
if (2 > 1) {
425-
api.enhanceEndpoints({
426-
endpoints: {
427-
query1: {
428-
// @ts-expect-error
429-
providesTags: ['new'],
430-
},
431-
query2: {
432-
// @ts-expect-error
433-
providesTags: ['missing'],
434-
},
435-
},
436-
})
437-
}
438423

439424
const enhanced = api.enhanceEndpoints({
440425
addTagTypes: ['new'],
@@ -461,22 +446,6 @@ describe('endpoint definition typings', () => {
461446
expect(consoleErrorSpy).toHaveBeenLastCalledWith(
462447
"Tag type 'missing' was used, but not specified in `tagTypes`!",
463448
)
464-
465-
// only type-test this part
466-
if (2 > 1) {
467-
enhanced.enhanceEndpoints({
468-
endpoints: {
469-
query1: {
470-
// returned `enhanced` api contains "new" enitityType
471-
providesTags: ['new'],
472-
},
473-
query2: {
474-
// @ts-expect-error
475-
providesTags: ['missing'],
476-
},
477-
},
478-
})
479-
}
480449
})
481450

482451
test('modify', () => {

packages/toolkit/src/tests/createAsyncThunk.test-d.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { TSVersion } from '@phryneas/ts-version'
12
import type {
23
AsyncThunk,
34
SerializedError,
@@ -11,8 +12,6 @@ import {
1112
createSlice,
1213
unwrapResult,
1314
} from '@reduxjs/toolkit'
14-
15-
import type { TSVersion } from '@phryneas/ts-version'
1615
import type { AxiosError } from 'axios'
1716
import apiRequest from 'axios'
1817
import type { AsyncThunkDispatchConfig } from '@internal/createAsyncThunk'
@@ -753,10 +752,11 @@ describe('type tests', () => {
753752

754753
expectTypeOf(n).toBeNumber()
755754

756-
if (1 < 2)
757-
// @ts-expect-error
758-
return api.rejectWithValue(5)
759-
if (1 < 2) return api.rejectWithValue('test')
755+
expectTypeOf(api.rejectWithValue).parameter(0).not.toBeNumber()
756+
757+
expectTypeOf(api.rejectWithValue).toBeCallableWith('test')
758+
759+
if (api) return api.rejectWithValue('test')
760760
return test1 + test2
761761
})
762762

@@ -783,7 +783,7 @@ describe('type tests', () => {
783783

784784
expectTypeOf(n).toBeNumber()
785785

786-
if (1 < 2) expectTypeOf(api.rejectWithValue).toBeCallableWith('test')
786+
expectTypeOf(api.rejectWithValue).toBeCallableWith('test')
787787

788788
expectTypeOf(api.rejectWithValue).parameter(0).not.toBeNumber()
789789

@@ -819,8 +819,7 @@ describe('type tests', () => {
819819

820820
expectTypeOf(n).toBeNumber()
821821

822-
if (1 < 2) return api.rejectWithValue(5)
823-
if (1 < 2) expectTypeOf(api.rejectWithValue).toBeCallableWith(5)
822+
expectTypeOf(api.rejectWithValue).toBeCallableWith(5)
824823

825824
expectTypeOf(api.rejectWithValue).parameter(0).not.toBeString()
826825

packages/toolkit/src/tests/utils/helpers.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function withProvider(store: Store<any>) {
4444
export const hookWaitFor = async (cb: () => void, time = 2000) => {
4545
const startedAt = Date.now()
4646

47-
while (true) {
47+
while (startedAt) {
4848
try {
4949
cb()
5050
return true
@@ -61,7 +61,7 @@ export const hookWaitFor = async (cb: () => void, time = 2000) => {
6161
export const fakeTimerWaitFor = async (cb: () => void, time = 2000) => {
6262
const startedAt = Date.now()
6363

64-
while (true) {
64+
while (startedAt) {
6565
try {
6666
cb()
6767
return true

0 commit comments

Comments
 (0)