Skip to content

Commit dc04cce

Browse files
committed
Fix no-constant-condition related problems
1 parent f2508fd commit dc04cce

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
@@ -103,6 +103,7 @@ const retryWithBackoff: BaseQueryEnhancer<
103103
}
104104
let retry = 0
105105

106+
// eslint-disable-next-line no-constant-condition
106107
while (true) {
107108
try {
108109
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
@@ -12,7 +12,7 @@ import type {
1212
TagTypesFromApi,
1313
} from '@reduxjs/toolkit/query'
1414
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query'
15-
import { HttpResponse, delay, http } from 'msw'
15+
import { delay, http, HttpResponse } from 'msw'
1616
import nodeFetch from 'node-fetch'
1717
import type { MockInstance } from 'vitest'
1818

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

423408
const enhanced = api.enhanceEndpoints({
424409
addTagTypes: ['new'],
@@ -442,22 +427,6 @@ describe('endpoint definition typings', () => {
442427
expect(spy).toHaveBeenCalledWith(
443428
"Tag type 'missing' was used, but not specified in `tagTypes`!",
444429
)
445-
446-
// only type-test this part
447-
if (2 > 1) {
448-
enhanced.enhanceEndpoints({
449-
endpoints: {
450-
query1: {
451-
// returned `enhanced` api contains "new" enitityType
452-
providesTags: ['new'],
453-
},
454-
query2: {
455-
// @ts-expect-error
456-
providesTags: ['missing'],
457-
},
458-
},
459-
})
460-
}
461430
})
462431

463432
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
@@ -49,7 +49,7 @@ export function withProvider(store: Store<any>) {
4949
export const hookWaitFor = async (cb: () => void, time = 2000) => {
5050
const startedAt = Date.now()
5151

52-
while (true) {
52+
while (startedAt) {
5353
try {
5454
cb()
5555
return true
@@ -66,7 +66,7 @@ export const hookWaitFor = async (cb: () => void, time = 2000) => {
6666
export const fakeTimerWaitFor = async (cb: () => void, time = 2000) => {
6767
const startedAt = Date.now()
6868

69-
while (true) {
69+
while (startedAt) {
7070
try {
7171
cb()
7272
return true

0 commit comments

Comments
 (0)