You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rtk-query/usage-with-typescript.mdx
+132
Original file line number
Diff line number
Diff line change
@@ -703,3 +703,135 @@ function AddPost() {
703
703
)
704
704
}
705
705
```
706
+
707
+
## Schema Validation
708
+
709
+
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.
710
+
711
+
When following the default approach of explicitly specifying type parameters for queries and mutations, the schemas will be required to match the types provided.
v.transform(titleCase), // fine - string -> string
784
+
),
785
+
published_at: v.pipe(
786
+
v.string(),
787
+
// highlight-next-line
788
+
v.transform((s) =>newDate(s)), // not allowed!
789
+
v.date(),
790
+
),
791
+
})
792
+
typePost=v.InferOutput<typeofpostSchema>
793
+
794
+
const api =createApi({
795
+
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
796
+
endpoints: (build) => ({
797
+
getPost: build.query<Post, { id:number }>({
798
+
query: ({ id }) =>`/post/${id}`,
799
+
responseSchema: postSchema,
800
+
}),
801
+
}),
802
+
})
803
+
```
804
+
805
+
Instead, transformation should be done with `transformResponse` and `transformErrorResponse` (when using `query`) or inside `queryFn` (when using `queryFn`).
0 commit comments