Skip to content

Commit

Permalink
Merge pull request #4095 from aryaemami59/fix-type-tests-setup
Browse files Browse the repository at this point in the history
Revamp type tests setup
  • Loading branch information
EskiMojo14 committed Jan 26, 2024
2 parents f5b07fe + 6b80fdd commit c7be31f
Show file tree
Hide file tree
Showing 61 changed files with 1,219 additions and 1,069 deletions.
11 changes: 6 additions & 5 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@
"tslib": "^1.10.0",
"tsup": "^7.2.0",
"tsx": "^3.12.2",
"typescript": "5.2",
"typescript": "^5.3.3",
"vitest": "^1.1.3",
"yargs": "^15.3.1"
},
"scripts": {
"clean": "rimraf dist",
"run-build": "tsup",
"build": "yarn rimraf dist && echo Compiling TS... && yarn tsc && yarn run-build",
"build-only": "yarn rimraf dist && yarn run-build",
"build": "yarn clean && echo Compiling TS... && yarn tsc -p tsconfig.build.json && yarn run-build",
"build-only": "yarn clean && yarn run-build",
"format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"",
"format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"",
"lint": "eslint src examples",
"test": "vitest --run",
"test": "vitest --run --typecheck",
"test:watch": "vitest --watch",
"type-tests": "yarn tsc -p src/tests/tsconfig.typetests.json && yarn tsc -p src/query/tests/tsconfig.typetests.json",
"type-tests": "yarn tsc -p tsconfig.test.json --noEmit",
"prepack": "yarn build"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Action, UnknownAction, Middleware } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import { createDynamicMiddleware } from '../index'
import { configureStore } from '../../configureStore'
import { expectExactType, expectType } from '../../tests/helpers'
import { expectExactType, expectType } from '../../tests/utils/typeTestHelpers'

const untypedInstance = createDynamicMiddleware()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ReactReduxContextValue } from 'react-redux'
import type { Action, UnknownAction, Middleware } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import { createDynamicMiddleware } from '../react'
import { expectExactType, expectType } from '../../tests/helpers'
import { expectExactType, expectType } from '../../tests/utils/typeTestHelpers'
/* eslint-disable no-lone-blocks */

interface AppDispatch extends ThunkDispatch<number, undefined, UnknownAction> {
Expand Down
70 changes: 34 additions & 36 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import type {
UnknownAction,
Selector,
ThunkAction,
ThunkDispatch,
UnknownAction,
} from '@reduxjs/toolkit'
import type { DependencyList } from 'react'
import {
useCallback,
useDebugValue,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react'
import { QueryStatus, skipToken } from '@reduxjs/toolkit/query'
import type {
QuerySubState,
SubscriptionOptions,
QueryKeys,
RootState,
} from '@reduxjs/toolkit/query'
import type {
Api,
ApiContext,
ApiEndpointMutation,
ApiEndpointQuery,
CoreModule,
EndpointDefinitions,
MutationActionCreatorResult,
MutationDefinition,
QueryDefinition,
QueryArgFrom,
ResultTypeFrom,
QueryResultSelectorResult,
MutationResultSelectorResult,
SkipToken,
PrefetchOptions,
QueryActionCreatorResult,
MutationActionCreatorResult,
QueryArgFrom,
QueryDefinition,
QueryKeys,
QueryResultSelectorResult,
QuerySubState,
ResultTypeFrom,
RootState,
SerializeQueryArgs,
Api,
ApiContext,
SkipToken,
SubscriptionOptions,
TSHelpersId,
TSHelpersNoInfer,
TSHelpersOverride,
ApiEndpointMutation,
ApiEndpointQuery,
CoreModule,
PrefetchOptions,
} from '@reduxjs/toolkit/query'
import { QueryStatus, skipToken } from '@reduxjs/toolkit/query'
import type { DependencyList } from 'react'
import {
useCallback,
useDebugValue,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react'

import { shallowEqual } from 'react-redux'
import type { ReactHooksModuleOptions } from './module'
import { useStableQueryArgs } from './useSerializedStableValue'
import type { BaseQueryFn } from '../baseQueryTypes'
import type { SubscriptionSelectors } from '../core/buildMiddleware/types'
import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs'
import type { UninitializedValue } from './constants'
import { UNINITIALIZED_VALUE } from './constants'
import type { ReactHooksModuleOptions } from './module'
import { useStableQueryArgs } from './useSerializedStableValue'
import { useShallowStableValue } from './useShallowStableValue'
import type { BaseQueryFn } from '../baseQueryTypes'
import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs'
import type { SubscriptionSelectors } from '../core/buildMiddleware/types'

// Copy-pasted from React-Redux
export const useIsomorphicLayoutEffect =
Expand Down Expand Up @@ -1026,7 +1024,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
[fixedCacheKey, promise, select]
)
const mutationSelector = useMemo(
() =>
(): Selector<RootState<Definitions, any, any>, any> =>
selectFromResult
? createSelector([selectDefaultResult], selectFromResult)
: selectDefaultResult,
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'

import { coreModule, buildCreateApi } from '@reduxjs/toolkit/query'
import { buildCreateApi, coreModule } from '@reduxjs/toolkit/query'
import { reactHooksModule, reactHooksModuleName } from './module'

export * from '@reduxjs/toolkit/query'
Expand All @@ -14,9 +14,9 @@ const createApi = /* @__PURE__ */ buildCreateApi(
)

export type {
TypedUseMutationResult,
TypedUseQueryHookResult,
TypedUseQueryStateResult,
TypedUseQuerySubscriptionResult,
TypedUseMutationResult,
} from './buildHooks'
export { createApi, reactHooksModule, reactHooksModuleName }
23 changes: 12 additions & 11 deletions packages/toolkit/src/query/react/module.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import type { MutationHooks, QueryHooks } from './buildHooks'
import { buildHooks } from './buildHooks'
import { isQueryDefinition, isMutationDefinition } from '../endpointDefinitions'
import type {
Api,
BaseQueryFn,
EndpointDefinitions,
QueryDefinition,
Module,
MutationDefinition,
QueryArgFrom,
QueryDefinition,
} from '@reduxjs/toolkit/query'
import type { Api, Module } from '../apiTypes'
import { capitalize } from '../utils'
import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions'
import { safeAssign } from '../tsHelpers'
import type { BaseQueryFn } from '@reduxjs/toolkit/query'
import { capitalize } from '../utils'
import type { MutationHooks, QueryHooks } from './buildHooks'
import { buildHooks } from './buildHooks'

import type { HooksWithUniqueNames } from './namedHooks'

import {
batch as rrBatch,
useDispatch as rrUseDispatch,
useSelector as rrUseSelector,
useStore as rrUseStore,
batch as rrBatch,
} from 'react-redux'
import { createSelector as _createSelector } from 'reselect'
import type { QueryKeys } from '../core/apiState'
import type { PrefetchOptions } from '../core/module'
import { countObjectKeys } from '../utils/countObjectKeys'
import { createSelector as _createSelector } from 'reselect'

export const reactHooksModuleName = /* @__PURE__ */ Symbol()
export type ReactHooksModule = typeof reactHooksModuleName
Expand Down Expand Up @@ -187,8 +188,8 @@ export const reactHooksModule = ({
const anyApi = api as any as Api<
any,
Record<string, any>,
string,
string,
any,
any,
ReactHooksModule
>
const { buildQueryHooks, buildMutationHook, usePrefetch } = buildHooks({
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/tests/buildCreateApi.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
createSelectorHook,
createStoreHook,
} from 'react-redux'
import { setupApiStore, useRenderCounter } from './helpers'
import { setupApiStore, useRenderCounter } from '../../tests/utils/helpers'

const MyContext = React.createContext<ReactReduxContextValue>(null as any)

Expand Down

0 comments on commit c7be31f

Please sign in to comment.