Skip to content

Commit 169c874

Browse files
committed
Fix no-constant-condition related problems
1 parent 05cdb3f commit 169c874

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
@@ -107,6 +107,7 @@ const retryWithBackoff: BaseQueryEnhancer<
107107
}
108108
let retry = 0
109109

110+
// eslint-disable-next-line no-constant-condition
110111
while (true) {
111112
try {
112113
const result = await baseQuery(args, api, extraOptions)

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

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

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

481450
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)