Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(react-query): update vitest type test correctly #6990

Merged

Conversation

manudeli
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Feb 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Visit Preview Mar 8, 2024 0:11am

Copy link

nx-cloud bot commented Feb 28, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 95e7528. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link

codesandbox-ci bot commented Feb 28, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 95e7528:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

Copy link
Contributor Author

@manudeli manudeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intention as comments

expectTypeOf<(typeof queryKey)[typeof dataTagSymbol]>().toEqualTypeOf<
InfiniteData<string>
>()
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary generics

@@ -3,17 +3,10 @@ import { fireEvent, render, waitFor } from '@testing-library/react'
import * as React from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { QueryCache, queryOptions, useQueries } from '..'
import {
createQueryClient,
expectTypeNotAny,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary expectTypeNotAny

import type {
QueryFunction,
QueryKey,
QueryObserverResult,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary QueryObserverResult

@@ -157,26 +152,24 @@ describe('useQueries', () => {
queryKey: key1,
queryFn: () => 'string',
select: (a) => {
expectTypeOf<string>(a)
expectTypeNotAny(a)
expectTypeOf(a).toEqualTypeOf<string>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check not any too.

expectTypeOf<QueryObserverResult<number, unknown>>(result4[1])
expectTypeOf<string | undefined>(result4[0].data)
expectTypeOf<number | undefined>(result4[1].data)
expectTypeOf(result4[0]).toEqualTypeOf<UseQueryResult<string, Error>>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why use toEqualTypeOf (Error type)
with toEqualTypeOf, We can strictly type check

Comment on lines -81 to -87
/**
* Assert the parameter is not typed as `any`
*/
export function expectTypeNotAny<T>(_: 0 extends 1 & T ? never : T): void {
return undefined
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary expectTypeNotAny by expectTypeOf().toEqualTypeOf

@manudeli manudeli marked this pull request as ready for review February 28, 2024 16:52
@manudeli manudeli changed the title test(react-query): update vitest type test code correctly (expectTypeOf) test(react-query): update vitest type test correctly Mar 6, 2024
@TkDodo TkDodo merged commit f9ecde2 into TanStack:main Mar 9, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants