Skip to content

Commit 2b8d2af

Browse files
authored
chore: turn on noUncheckedIndexedAccess compiler flag (TanStack#2341)
1 parent 0de83ae commit 2b8d2af

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/core/tests/queryClient.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('queryClient', () => {
344344
const data = {
345345
pages: ['data'],
346346
pageParams: [undefined],
347-
}
347+
} as const
348348

349349
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
350350
Promise.resolve(data.pages[0])

src/core/tests/utils.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ describe('core/utils', () => {
295295
expect(result.todos).not.toBe(next.todos)
296296
expect(result.todos[0]).not.toBe(prev.todos[0])
297297
expect(result.todos[0]).not.toBe(next.todos[0])
298-
expect(result.todos[0].id).toBe(next.todos[0].id)
299-
expect(result.todos[0].meta).toBe(prev.todos[0].meta)
300-
expect(result.todos[0].state).not.toBe(next.todos[0].state)
301-
expect(result.todos[0].state.done).toBe(next.todos[0].state.done)
298+
expect(result.todos[0]?.id).toBe(next.todos[0]?.id)
299+
expect(result.todos[0]?.meta).toBe(prev.todos[0]?.meta)
300+
expect(result.todos[0]?.state).not.toBe(next.todos[0]?.state)
301+
expect(result.todos[0]?.state.done).toBe(next.todos[0]?.state.done)
302302
expect(result.todos[1]).toBe(prev.todos[1])
303303
})
304304
})

src/react/tests/useQuery.test.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ describe('useQuery', () => {
818818
expect(states[0]).toMatchObject({ data: undefined, isFetching: true })
819819
expect(states[1]).toMatchObject({ data: 'test', isFetching: false })
820820
expect(states[2]).toMatchObject({ data: 'test', isFetching: false })
821-
expect(states[1].dataUpdatedAt).not.toBe(states[2].dataUpdatedAt)
821+
expect(states[1]?.dataUpdatedAt).not.toBe(states[2]?.dataUpdatedAt)
822822
})
823823

824824
it('should track properties and only re-render when a tracked property changes', async () => {
@@ -1039,13 +1039,13 @@ describe('useQuery', () => {
10391039

10401040
await waitFor(() => expect(states.length).toBe(4))
10411041

1042-
const todos = states[2].data!
1043-
const todo1 = todos[0]
1044-
const todo2 = todos[1]
1042+
const todos = states[2]?.data
1043+
const todo1 = todos?.[0]
1044+
const todo2 = todos?.[1]
10451045

1046-
const newTodos = states[3].data!
1047-
const newTodo1 = newTodos[0]
1048-
const newTodo2 = newTodos[1]
1046+
const newTodos = states[3]?.data
1047+
const newTodo1 = newTodos?.[0]
1048+
const newTodo2 = newTodos?.[1]
10491049

10501050
expect(todos).toEqual(result1)
10511051
expect(newTodos).toEqual(result2)
@@ -1465,7 +1465,7 @@ describe('useQuery', () => {
14651465
status: 'error',
14661466
isPreviousData: false,
14671467
})
1468-
expect(states[7].error).toHaveProperty('message', 'Error test')
1468+
expect(states[7]?.error).toHaveProperty('message', 'Error test')
14691469

14701470
consoleMock.mockRestore()
14711471
})
@@ -2304,7 +2304,7 @@ describe('useQuery', () => {
23042304

23052305
await sleep(20)
23062306

2307-
expect(states[1].data).toEqual([key, variables])
2307+
expect(states[1]?.data).toEqual([key, variables])
23082308
})
23092309

23102310
it('should not refetch query on focus when `enabled` is set to `false`', async () => {

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"noImplicitThis": true,
1212
"noUnusedLocals": true,
1313
"noUnusedParameters": true,
14+
"noUncheckedIndexedAccess": true,
1415
"skipLibCheck": true,
1516
"strict": true,
1617
"types": ["jest"],

0 commit comments

Comments
 (0)