11import { describe , expectTypeOf , test } from "vitest" ;
22import { makeClientWithExplicitTypes } from "../core/api-client" ;
33import { Client } from "../test-util/generated-api-types" ;
4+ import { Color } from "../test-util/cat-api" ;
45
56describe ( "Generated API Client" , ( ) => {
67 describe ( "single resource" , ( ) => {
@@ -17,20 +18,20 @@ describe("Generated API Client", () => {
1718 let updateOutput = client . cats ( "shiro" ) . update ( { color : "white" } ) ;
1819 let retrieveLitterOutput = client . cats ( "shiro" ) . litter . retrieveLitter ( ) ;
1920
20- expectTypeOf ( listOutput ) . toEqualTypeOf <
21- Promise < { name : string ; color : string } [ ] >
21+ expectTypeOf ( listOutput ) . toMatchTypeOf <
22+ Promise < { name : string ; color : Color } [ ] >
2223 > ( ) ;
23- expectTypeOf ( createOutput ) . toEqualTypeOf <
24- Promise < { name : string ; color : string } >
24+ expectTypeOf ( createOutput ) . toMatchTypeOf <
25+ Promise < { name : string ; color : Color } >
2526 > ( ) ;
2627 expectTypeOf ( retrieveOutput ) . toEqualTypeOf <
27- Promise < { name : string ; color : string } >
28+ Promise < { name : string ; color : Color } >
2829 > ( ) ;
29- expectTypeOf ( updateOutput ) . toEqualTypeOf <
30- Promise < { name : string ; color : string } >
30+ expectTypeOf ( updateOutput ) . toMatchTypeOf <
31+ Promise < { name : string ; color : Color } >
3132 > ( ) ;
3233 expectTypeOf ( retrieveLitterOutput ) . toEqualTypeOf <
33- Promise < { name : string ; color : string } [ ] >
34+ Promise < { name : string ; color : Color } [ ] >
3435 > ( ) ;
3536 } ) ;
3637
@@ -48,23 +49,23 @@ describe("Generated API Client", () => {
4849
4950 expectTypeOf ( listOutput ) . toEqualTypeOf < {
5051 queryKey : string [ ] ;
51- queryFn : ( ) => Promise < { name : string ; color : string } [ ] > ;
52+ queryFn : ( ) => Promise < { name : string ; color : Color } [ ] > ;
5253 } > ( ) ;
5354 expectTypeOf ( createOutput ) . toEqualTypeOf < {
5455 queryKey : string [ ] ;
55- queryFn : ( ) => Promise < { name : string ; color : string } > ;
56+ queryFn : ( ) => Promise < { name : string ; color : Color } > ;
5657 } > ( ) ;
5758 expectTypeOf ( retrieveOutput ) . toEqualTypeOf < {
5859 queryKey : string [ ] ;
59- queryFn : ( ) => Promise < { name : string ; color : string } > ;
60+ queryFn : ( ) => Promise < { name : string ; color : Color } > ;
6061 } > ( ) ;
6162 expectTypeOf ( updateOutput ) . toEqualTypeOf < {
6263 queryKey : string [ ] ;
63- queryFn : ( ) => Promise < { name : string ; color : string } > ;
64+ queryFn : ( ) => Promise < { name : string ; color : Color } > ;
6465 } > ( ) ;
6566 expectTypeOf ( retrieveLitterOutput ) . toEqualTypeOf < {
6667 queryKey : string [ ] ;
67- queryFn : ( ) => Promise < { name : string ; color : string } [ ] > ;
68+ queryFn : ( ) => Promise < { name : string ; color : Color } [ ] > ;
6869 } > ( ) ;
6970 } ) ;
7071 } ) ;
@@ -77,8 +78,8 @@ describe("Generated API Client", () => {
7778 let catListOutput = client . cats . list ( ) ;
7879 let dogListOutput = client . dogs . list ( ) ;
7980
80- expectTypeOf ( catListOutput ) . toEqualTypeOf <
81- Promise < { name : string ; color : string } [ ] >
81+ expectTypeOf ( catListOutput ) . toMatchTypeOf <
82+ Promise < { name : string ; color : Color } [ ] >
8283 > ( ) ;
8384 expectTypeOf ( dogListOutput ) . toEqualTypeOf <
8485 Promise < { name : string ; color : string } [ ] >
@@ -99,8 +100,19 @@ describe("Generated API Client", () => {
99100
100101 test ( "can handle native enums" , ( ) => {
101102 expectTypeOf (
102- client . users ( "foo" ) . update . useSuspenseQuery ( { } ) . data . accountType
103- ) . toEqualTypeOf < "admin" | "free" | "paid" > ( ) ;
103+ client . users ( "foo" ) . update ( { } ) . useSuspenseQuery ( ) . data . accountType
104+ ) . toMatchTypeOf < "admin" | "free" | "paid" > ( ) ;
105+ } ) ;
106+ } ) ;
107+
108+ describe ( "extensions" , ( ) => {
109+ const config = { basePath : "/api" as const } ;
110+ const client = makeClientWithExplicitTypes < Client > ( config ) ;
111+
112+ test ( "expects query params" , ( ) => {
113+ expectTypeOf (
114+ client . cats . list ( { color : "black" } ) . useSuspenseQuery
115+ ) . toBeFunction ( ) ;
104116 } ) ;
105117 } ) ;
106118} ) ;
0 commit comments