diff --git a/docs/rtk-query/api/createApi.mdx b/docs/rtk-query/api/createApi.mdx index d881735cfb..f2a1f592ac 100644 --- a/docs/rtk-query/api/createApi.mdx +++ b/docs/rtk-query/api/createApi.mdx @@ -221,6 +221,20 @@ export type QueryDefinition< updateCachedData, // available for query endpoints only }: QueryCacheLifecycleApi, ): Promise + + argSchema?: StandardSchemaV1 + + /* only available with `query`, not `queryFn` */ + rawResponseSchema?: StandardSchemaV1> + + responseSchema?: StandardSchemaV1 + + /* only available with `query`, not `queryFn` */ + rawErrorResponseSchema?: StandardSchemaV1> + + errorResponseSchema?: StandardSchemaV1> + + metaSchema?: StandardSchemaV1> } ``` @@ -469,6 +483,26 @@ You can set this globally in `createApi`, but you can also override the default If you specify `track: false` when manually dispatching queries, RTK Query will not be able to automatically refetch for you. ::: +### `onSchemaFailure` + +[summary](docblock://query/createApi.ts?token=CreateApiOptions.onSchemaFailure) + +[examples](docblock://query/createApi.ts?token=CreateApiOptions.onSchemaFailure) + +:::note +You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `onSchemaFailure` to each individual endpoint definition. +::: + +### `skipSchemaValidation` + +[summary](docblock://query/createApi.ts?token=CreateApiOptions.skipSchemaValidation) + +[examples](docblock://query/createApi.ts?token=CreateApiOptions.skipSchemaValidation) + +:::note +You can set this globally in `createApi`, but you can also override the default value and have more granular control by passing `skipSchemaValidation` to each individual endpoint definition. +::: + ## Endpoint Definition Parameters ### `query` @@ -792,6 +826,64 @@ async function onCacheEntryAdded( ): Promise ``` +### Schema Validation + +Endpoints can have schemas for runtime validation of various values. Any [Standard Schema](https://standardschema.dev/) compliant library can be used. + +:::warning + +Schema failures are treated as _fatal_, meaning that normal error handling such as tag invalidation will not be executed. + +::: + +#### `argSchema` + +_(optional)_ + +[summary](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.argSchema) + +[examples](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.argSchema) + +#### `responseSchema` + +_(optional)_ + +[summary](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.responseSchema) + +[examples](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.responseSchema) + +#### `rawResponseSchema` + +_(optional, not applicable with `queryFn`)_ + +[summary](docblock://query/endpointDefinitions.ts?token=EndpointDefinitionWithQuery.rawResponseSchema) + +[examples](docblock://query/endpointDefinitions.ts?token=EndpointDefinitionWithQuery.rawResponseSchema) + +#### `errorResponseSchema` + +_(optional)_ + +[summary](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.errorResponseSchema) + +[examples](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.errorResponseSchema) + +#### `rawErrorResponseSchema` + +_(optional, not applicable with `queryFn`)_ + +[summary](docblock://query/endpointDefinitions.ts?token=EndpointDefinitionWithQuery.rawErrorResponseSchema) + +[examples](docblock://query/endpointDefinitions.ts?token=EndpointDefinitionWithQuery.rawErrorResponseSchema) + +#### `metaSchema` + +_(optional)_ + +[summary](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.metaSchema) + +[examples](docblock://query/endpointDefinitions.ts?token=CommonEndpointDefinition.metaSchema) + ## Return value See [the "created Api" API reference](./created-api/overview) diff --git a/docs/rtk-query/usage-with-typescript.mdx b/docs/rtk-query/usage-with-typescript.mdx index a9f67bbbd9..061682c191 100644 --- a/docs/rtk-query/usage-with-typescript.mdx +++ b/docs/rtk-query/usage-with-typescript.mdx @@ -703,3 +703,135 @@ function AddPost() { ) } ``` + +## Schema Validation + +Endpoints can have schemas for runtime validation of various values. Any [Standard Schema](https://standardschema.dev/) compliant library can be used. See [API reference](./api/createApi.mdx#schema-validation) for full list of available schemas. + +When following the default approach of explicitly specifying type parameters for queries and mutations, the schemas will be required to match the types provided. + +```ts title="Explicitly typed endpoint" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' + +const postSchema = v.object({ + id: v.number(), + name: v.string(), +}) +type Post = v.InferOutput + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: '/' }), + endpoints: (build) => ({ + getPost: build.query({ + query: ({ id }) => `/post/${id}`, + responseSchema: postSchema, // errors if type mismatch + }), + }), +}) +``` + +Schemas can also be used as a source of inference, meaning that the type parameters can be omitted. + +```ts title="Implicitly typed endpoint" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' + +const postSchema = v.object({ + id: v.number(), + name: v.string(), +}) +type Post = v.InferOutput + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: '/' }), + endpoints: (build) => ({ + getPost: build.query({ + // infer arg from here + query: ({ id }: { id: number }) => `/post/${id}`, + // infer result from here + responseSchema: postSchema, + }), + getTransformedPost: build.query({ + // infer arg from here + query: ({ id }: { id: number }) => `/post/${id}`, + // infer untransformed result from here + rawResponseSchema: postSchema, + // infer transformed result from here + transformResponse: (response) => ({ + ...response, + published_at: new Date(response.published_at), + }), + }), + }), +}) +``` + +:::warning + +Schemas should _not_ perform any transformation that would change the type of the value. + +```ts title="Incorrect usage" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' +import { titleCase } from 'lodash' + +const postSchema = v.object({ + id: v.number(), + name: v.pipe( + v.string(), + v.transform(titleCase), // fine - string -> string + ), + published_at: v.pipe( + v.string(), + // highlight-next-line + v.transform((s) => new Date(s)), // not allowed! + v.date(), + ), +}) +type Post = v.InferOutput + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: '/' }), + endpoints: (build) => ({ + getPost: build.query({ + query: ({ id }) => `/post/${id}`, + responseSchema: postSchema, + }), + }), +}) +``` + +Instead, transformation should be done with `transformResponse` and `transformErrorResponse` (when using `query`) or inside `queryFn` (when using `queryFn`). + +```ts title="Correct usage" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' + +const postSchema = v.object({ + id: v.number(), + name: v.string(), + published_at: v.string(), +}) +type RawPost = v.InferOutput +type Post = Omit & { published_at: Date } + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: '/' }), + endpoints: (build) => ({ + getPost: build.query({ + query: ({ id }) => `/post/${id}`, + // use rawResponseSchema to validate *before* transformation + rawResponseSchema: postSchema, + // highlight-start + transformResponse: (response) => ({ + ...response, + published_at: new Date(response.published_at), + }), + // highlight-end + }), + }), +}) +``` + +::: diff --git a/docs/rtk-query/usage/infinite-queries.mdx b/docs/rtk-query/usage/infinite-queries.mdx index c43dd02572..bbd53e3e33 100644 --- a/docs/rtk-query/usage/infinite-queries.mdx +++ b/docs/rtk-query/usage/infinite-queries.mdx @@ -531,3 +531,59 @@ const projectsApi = createApi({ }), }) ``` + +## Runtime Validation using Schemas + +Endpoints can use any [Standard Schema](https://standardschema.dev/) compliant library for runtime validation of various values. See [API reference](../api/createApi.mdx#schema-validation) for full list of available schemas. + +Most commonly, you'll want to use `responseSchema` to validate the response from the server (or `rawResponseSchema` when using `transformResponse`). + +```ts title="Using responseSchema" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' + +const pokemonSchema = v.object({ + id: v.number(), + name: v.string(), +}) +type Pokemon = v.InferOutput +const transformedPokemonSchema = v.object({ + ...pokemonSchema.entries, + id: v.string(), +}) +type TransformedPokemon = v.InferOutput + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: 'https://example.com/pokemon' }), + endpoints: (build) => ({ + getInfinitePokemon: build.infiniteQuery({ + query: ({ queryArg, pageParam }) => `type/${queryArg}?page=${pageParam}`, + // argSchema for infinite queries must have both queryArg and pageParam + argSchema: v.object({ + queryArg: v.string(), + pageParam: v.number(), + }), + responseSchema: v.array(pokemonSchema), + }), + getTransformedPokemon: build.infiniteQuery< + TransformedPokemon[], + string, + number + >({ + query: ({ queryArg, pageParam }) => `type/${queryArg}?page=${pageParam}`, + argSchema: v.object({ + queryArg: v.string(), + pageParam: v.number(), + }), + rawResponseSchema: v.array(pokemonSchema), + transformResponse: (response) => + response.map((pokemon) => ({ + ...pokemon, + id: String(pokemon.id), + })), + // responseSchema can still be provided, to validate the transformed response + responseSchema: v.array(transformedPokemonSchema), + }), + }), +}) +``` diff --git a/docs/rtk-query/usage/mutations.mdx b/docs/rtk-query/usage/mutations.mdx index 15a3b2e8f4..d1c38300e1 100644 --- a/docs/rtk-query/usage/mutations.mdx +++ b/docs/rtk-query/usage/mutations.mdx @@ -326,3 +326,60 @@ export const { allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" > + +## Runtime Validation using Schemas + +Endpoints can use any [Standard Schema](https://standardschema.dev/) compliant library for runtime validation of various values. See [API reference](../api/createApi.mdx#schema-validation) for full list of available schemas. + +Most commonly, you'll want to use `responseSchema` to validate the response from the server (or `rawResponseSchema` when using `transformResponse`). + +```ts title="Using responseSchema" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' + +const postSchema = v.object({ + id: v.number(), + name: v.string(), + published_at: v.string(), +}) +type Post = v.InferOutput +const transformedPost = v.object({ + ...postSchema.entries, + published_at: v.date(), +}) +type TransformedPost = v.InferOutput + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: '/' }), + endpoints: (build) => ({ + updatePost: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `post/${id}`, + method: 'PUT', + body, + } + }, + responseSchema: postSchema, + }), + updatePostWithTransform: build.mutation>({ + query(data) { + const { id, ...body } = data + return { + url: `post/${id}`, + method: 'PUT', + body, + } + }, + rawResponseSchema: postSchema, + transformResponse: (response) => ({ + ...response, + published_at: new Date(response.published_at), + }), + // responseSchema can still be provided, to validate the transformed response + responseSchema: transformedPost, + }), + }), +}) +``` diff --git a/docs/rtk-query/usage/queries.mdx b/docs/rtk-query/usage/queries.mdx index 6f185aedf9..ccd98eb74c 100644 --- a/docs/rtk-query/usage/queries.mdx +++ b/docs/rtk-query/usage/queries.mdx @@ -350,6 +350,48 @@ const { status, data, error, refetch } = dispatch( ::: +## Runtime Validation using Schemas + +Endpoints can use any [Standard Schema](https://standardschema.dev/) compliant library for runtime validation of various values. See [API reference](../api/createApi.mdx#schema-validation) for full list of available schemas. + +Most commonly, you'll want to use `responseSchema` to validate the response from the server (or `rawResponseSchema` when using `transformResponse`). + +```ts title="Using responseSchema" no-transpile +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import * as v from 'valibot' + +const postSchema = v.object({ + id: v.number(), + name: v.string(), +}) +type Post = v.InferOutput +const transformedPost = v.object({ + ...postSchema.entries, + published_at: v.date(), +}) +type TransformedPost = v.InferOutput + +const api = createApi({ + baseQuery: fetchBaseQuery({ baseUrl: '/' }), + endpoints: (build) => ({ + getPost: build.query({ + query: ({ id }) => `/post/${id}`, + responseSchema: postSchema, + }), + getTransformedPost: build.query({ + query: ({ id }) => `/post/${id}`, + rawResponseSchema: postSchema, + transformResponse: (response) => ({ + ...response, + published_at: new Date(response.published_at), + }), + // responseSchema can still be provided, to validate the transformed response + responseSchema: transformedPost, + }), + }), +}) +``` + ## Example: Observing caching behavior This example demonstrates request deduplication and caching behavior: diff --git a/packages/toolkit/src/query/createApi.ts b/packages/toolkit/src/query/createApi.ts index 31fde60be8..4b5cf2886b 100644 --- a/packages/toolkit/src/query/createApi.ts +++ b/packages/toolkit/src/query/createApi.ts @@ -214,7 +214,59 @@ export interface CreateApiOptions< NoInfer > + /** + * A function that is called when a schema validation fails. + * + * Gets called with a `NamedSchemaError` and an object containing the endpoint name, the type of the endpoint, the argument passed to the endpoint, and the query cache key (if applicable). + * + * `NamedSchemaError` has the following properties: + * - `issues`: an array of issues that caused the validation to fail + * - `value`: the value that was passed to the schema + * - `schemaName`: the name of the schema that was used to validate the value (e.g. `argSchema`) + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * }), + * }), + * onSchemaFailure: (error, info) => { + * console.error(error, info) + * }, + * }) + * ``` + */ onSchemaFailure?: SchemaFailureHandler + /** + * Defaults to `false`. + * + * If set to `true`, will skip schema validation for all endpoints, unless overridden by the endpoint. + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * skipSchemaValidation: process.env.NODE_ENV === "test", // skip schema validation in tests, since we'll be mocking the response + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * responseSchema: v.object({ id: v.number(), name: v.string() }), + * }), + * }) + * }) + * ``` + */ skipSchemaValidation?: boolean } diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index c19488c1a2..496dbbedb1 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -40,6 +40,7 @@ import type { import { isNotNullish } from './utils' import type { NamedSchemaError } from './standardSchema' +const rawResultType = /* @__PURE__ */ Symbol() const resultType = /* @__PURE__ */ Symbol() const baseQuery = /* @__PURE__ */ Symbol() @@ -55,7 +56,7 @@ export type SchemaFailureHandler = ( info: SchemaFailureInfo, ) => void -type EndpointDefinitionWithQuery< +export type EndpointDefinitionWithQuery< QueryArg, BaseQuery extends BaseQueryFn, ResultType, @@ -118,14 +119,58 @@ type EndpointDefinitionWithQuery< arg: QueryArg, ): unknown - /** A schema for the result *before* it's passed to `transformResponse` */ + /** + * A schema for the result *before* it's passed to `transformResponse`. + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const postSchema = v.object({ id: v.number(), name: v.string() }) + * type Post = v.InferOutput + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * endpoints: (build) => ({ + * getPostName: build.query({ + * query: ({ id }) => `/post/${id}`, + * rawResponseSchema: postSchema, + * transformResponse: (post) => post.name, + * }), + * }) + * }) + * ``` + */ rawResponseSchema?: StandardSchemaV1 - /** A schema for the error object returned by the `query` or `queryFn`, *before* it's passed to `transformErrorResponse` */ + /** + * A schema for the error object returned by the `query` or `queryFn`, *before* it's passed to `transformErrorResponse`. + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * import {customBaseQuery, baseQueryErrorSchema} from "./customBaseQuery" + * + * const api = createApi({ + * baseQuery: customBaseQuery, + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * rawErrorResponseSchema: baseQueryErrorSchema, + * transformErrorResponse: (error) => error.data, + * }), + * }) + * }) + * ``` + */ rawErrorResponseSchema?: StandardSchemaV1> } -type EndpointDefinitionWithQueryFn< +export type EndpointDefinitionWithQueryFn< QueryArg, BaseQuery extends BaseQueryFn, ResultType, @@ -193,32 +238,102 @@ type BaseEndpointTypes = { ResultType: ResultType } -export type BaseEndpointDefinition< +interface CommonEndpointDefinition< QueryArg, BaseQuery extends BaseQueryFn, ResultType, - RawResultType extends BaseQueryResult = BaseQueryResult, -> = ( - | ([CastAny, {}>] extends [NEVER] - ? never - : EndpointDefinitionWithQuery< - QueryArg, - BaseQuery, - ResultType, - RawResultType - >) - | EndpointDefinitionWithQueryFn -) & { - /** A schema for the arguments to be passed to the `query` or `queryFn` */ +> { + /** + * A schema for the arguments to be passed to the `query` or `queryFn`. + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * argSchema: v.object({ id: v.number() }), + * }), + * }) + * }) + * ``` + */ argSchema?: StandardSchemaV1 - /** A schema for the result (including `transformResponse` if provided) */ + /** + * A schema for the result (including `transformResponse` if provided). + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const postSchema = v.object({ id: v.number(), name: v.string() }) + * type Post = v.InferOutput + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * responseSchema: postSchema, + * }), + * }) + * }) + * ``` + */ responseSchema?: StandardSchemaV1 - /** A schema for the error object returned by the `query` or `queryFn` (including `transformErrorResponse` if provided) */ + /** + * A schema for the error object returned by the `query` or `queryFn` (including `transformErrorResponse` if provided). + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * import { customBaseQuery, baseQueryErrorSchema } from "./customBaseQuery" + * + * const api = createApi({ + * baseQuery: customBaseQuery, + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * errorResponseSchema: baseQueryErrorSchema, + * }), + * }) + * }) + * ``` + */ errorResponseSchema?: StandardSchemaV1> - /** A schema for the `meta` property returned by the `query` or `queryFn` */ + /** + * A schema for the `meta` property returned by the `query` or `queryFn`. + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * import { customBaseQuery, baseQueryMetaSchema } from "./customBaseQuery" + * + * const api = createApi({ + * baseQuery: customBaseQuery, + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * metaSchema: baseQueryMetaSchema, + * }), + * }) + * }) + * ``` + */ metaSchema?: StandardSchemaV1> /** @@ -235,14 +350,88 @@ export type BaseEndpointDefinition< */ structuralSharing?: boolean + /** + * A function that is called when a schema validation fails. + * + * Gets called with a `NamedSchemaError` and an object containing the endpoint name, the type of the endpoint, the argument passed to the endpoint, and the query cache key (if applicable). + * + * `NamedSchemaError` has the following properties: + * - `issues`: an array of issues that caused the validation to fail + * - `value`: the value that was passed to the schema + * - `schemaName`: the name of the schema that was used to validate the value (e.g. `argSchema`) + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * onSchemaFailure: (error, info) => { + * console.error(error, info) + * }, + * }), + * }) + * }) + * ``` + */ onSchemaFailure?: SchemaFailureHandler + + /** + * Defaults to `false`. + * + * If set to `true`, will skip schema validation for this endpoint. + * Overrides the global setting. + * + * @example + * ```ts + * // codeblock-meta no-transpile + * import { createApi } from '@reduxjs/toolkit/query/react' + * import * as v from "valibot" + * + * const api = createApi({ + * baseQuery: fetchBaseQuery({ baseUrl: '/' }), + * endpoints: (build) => ({ + * getPost: build.query({ + * query: ({ id }) => `/post/${id}`, + * responseSchema: v.object({ id: v.number(), name: v.string() }), + * skipSchemaValidation: process.env.NODE_ENV === "test", // skip schema validation in tests, since we'll be mocking the response + * }), + * }) + * }) + * ``` + */ skipSchemaValidation?: boolean +} - /* phantom type */ - [resultType]?: ResultType - /* phantom type */ - [baseQuery]?: BaseQuery -} & HasRequiredProps< +export type BaseEndpointDefinition< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + RawResultType extends BaseQueryResult = BaseQueryResult, +> = ( + | ([CastAny, {}>] extends [NEVER] + ? never + : EndpointDefinitionWithQuery< + QueryArg, + BaseQuery, + ResultType, + RawResultType + >) + | EndpointDefinitionWithQueryFn +) & + CommonEndpointDefinition & { + /* phantom type */ + [rawResultType]?: RawResultType + /* phantom type */ + [resultType]?: ResultType + /* phantom type */ + [baseQuery]?: BaseQuery + } & HasRequiredProps< BaseQueryExtraOptions, { extraOptions: BaseQueryExtraOptions }, { extraOptions?: BaseQueryExtraOptions } diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 86ee665d82..ae78077a6d 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -161,7 +161,7 @@ export type TypedUseQueryHookResult< > = TypedUseQueryStateResult & TypedUseQuerySubscriptionResult -type UseQuerySubscriptionOptions = SubscriptionOptions & { +export type UseQuerySubscriptionOptions = SubscriptionOptions & { /** * Prevents a query from automatically running. * diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index b042530c54..a850b8eaa9 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -33,6 +33,7 @@ const config: Config = { 'index.ts', 'query/index.ts', 'query/createApi.ts', + 'query/endpointDefinitions.ts', 'query/react/index.ts', 'query/react/ApiProvider.tsx', ],