Skip to content

Commit

Permalink
Replace any with unknown inside Equals conditional type
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Jan 27, 2024
1 parent 1ae8a62 commit 6c7c165
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/tests/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export function expectType<T>(t: T): T {
type Equals<T, U> = IsAny<
T,
never,
IsAny<U, never, [T] extends [U] ? ([U] extends [T] ? any : never) : never>
IsAny<U, never, [T] extends [U] ? ([U] extends [T] ? unknown : never) : never>
>
export function expectExactType<T>(t: T) {
return <U extends T>(u: U & Equals<T, U>) => {}
Expand Down
5 changes: 4 additions & 1 deletion packages/toolkit/src/query/tests/unionTypes.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { SerializedError } from '@reduxjs/toolkit'
import type {
FetchBaseQueryError,
TypedUseMutationResult,
TypedUseQueryHookResult,
TypedUseQueryStateResult,
TypedUseQuerySubscriptionResult,
TypedUseMutationResult,
} from '@reduxjs/toolkit/query/react'
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import { expectExactType, expectType } from './helpers'
Expand Down Expand Up @@ -123,13 +123,15 @@ describe.skip('TS only tests', () => {
}

expectExactType('' as string | undefined)(result.currentData)
// @ts-expect-error
expectExactType('' as string)(result.currentData)

if (result.isSuccess) {
if (!result.isFetching) {
expectExactType('' as string)(result.currentData)
} else {
expectExactType('' as string | undefined)(result.currentData)
// @ts-expect-error
expectExactType('' as string)(result.currentData)
}
}
Expand Down Expand Up @@ -357,6 +359,7 @@ describe.skip('TS only tests', () => {
const { refetch, ...useQueryResultWithoutMethods } = useQueryResult
expectExactType(useQueryStateResult)(useQueryResultWithoutMethods)
expectExactType(useQueryStateWithSelectFromResult)(
// @ts-expect-error
useQueryResultWithoutMethods
)
expectType<ReturnType<ReturnType<typeof api.endpoints.test.select>>>(
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function expectType<T>(t: T): T {
type Equals<T, U> = IsAny<
T,
never,
IsAny<U, never, [T] extends [U] ? ([U] extends [T] ? any : never) : never>
IsAny<U, never, [T] extends [U] ? ([U] extends [T] ? unknown : never) : never>
>
export function expectExactType<T>(t: T) {
return <U extends T>(u: U & Equals<T, U>) => {}
Expand Down

0 comments on commit 6c7c165

Please sign in to comment.