Skip to content

Commit e5eddf7

Browse files
committed
Fix no-constant-condition related problems
1 parent d74519b commit e5eddf7

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
@@ -13,7 +13,7 @@ import type {
1313
TagTypesFromApi,
1414
} from '@reduxjs/toolkit/query'
1515
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query'
16-
import { HttpResponse, delay, http } from 'msw'
16+
import { delay, http, HttpResponse } from 'msw'
1717
import nodeFetch from 'node-fetch'
1818

1919
beforeAll(() => {
@@ -405,21 +405,6 @@ describe('endpoint definition typings', () => {
405405
const storeRef = setupApiStore(api, undefined, {
406406
withoutTestLifecycles: true,
407407
})
408-
// only type-test this part
409-
if (2 > 1) {
410-
api.enhanceEndpoints({
411-
endpoints: {
412-
query1: {
413-
// @ts-expect-error
414-
providesTags: ['new'],
415-
},
416-
query2: {
417-
// @ts-expect-error
418-
providesTags: ['missing'],
419-
},
420-
},
421-
})
422-
}
423408

424409
const enhanced = api.enhanceEndpoints({
425410
addTagTypes: ['new'],
@@ -446,22 +431,6 @@ describe('endpoint definition typings', () => {
446431
expect(consoleErrorSpy).toHaveBeenLastCalledWith(
447432
"Tag type 'missing' was used, but not specified in `tagTypes`!",
448433
)
449-
450-
// only type-test this part
451-
if (2 > 1) {
452-
enhanced.enhanceEndpoints({
453-
endpoints: {
454-
query1: {
455-
// returned `enhanced` api contains "new" enitityType
456-
providesTags: ['new'],
457-
},
458-
query2: {
459-
// @ts-expect-error
460-
providesTags: ['missing'],
461-
},
462-
},
463-
})
464-
}
465434
})
466435

467436
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

@@ -745,10 +744,11 @@ describe('type tests', () => {
745744

746745
expectTypeOf(n).toBeNumber()
747746

748-
if (1 < 2)
749-
// @ts-expect-error
750-
return api.rejectWithValue(5)
751-
if (1 < 2) return api.rejectWithValue('test')
747+
expectTypeOf(api.rejectWithValue).parameter(0).not.toBeNumber()
748+
749+
expectTypeOf(api.rejectWithValue).toBeCallableWith('test')
750+
751+
if (api) return api.rejectWithValue('test')
752752
return test1 + test2
753753
})
754754

@@ -775,7 +775,7 @@ describe('type tests', () => {
775775

776776
expectTypeOf(n).toBeNumber()
777777

778-
if (1 < 2) expectTypeOf(api.rejectWithValue).toBeCallableWith('test')
778+
expectTypeOf(api.rejectWithValue).toBeCallableWith('test')
779779

780780
expectTypeOf(api.rejectWithValue).parameter(0).not.toBeNumber()
781781

@@ -811,8 +811,7 @@ describe('type tests', () => {
811811

812812
expectTypeOf(n).toBeNumber()
813813

814-
if (1 < 2) return api.rejectWithValue(5)
815-
if (1 < 2) expectTypeOf(api.rejectWithValue).toBeCallableWith(5)
814+
expectTypeOf(api.rejectWithValue).toBeCallableWith(5)
816815

817816
expectTypeOf(api.rejectWithValue).parameter(0).not.toBeString()
818817

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)