@@ -17,6 +17,7 @@ describe('API routes', () => {
17
17
it ( 'generates types for routes' , ( ) => {
18
18
expectTypeOf ( $fetch ( '/api/hello' ) ) . toEqualTypeOf < Promise < string > > ( )
19
19
expectTypeOf ( $fetch ( '/api/hey' ) ) . toEqualTypeOf < Promise < { foo : string , baz : string } > > ( )
20
+ expectTypeOf ( $fetch ( '/api/union' ) ) . toEqualTypeOf < Promise < { type : 'a' , foo : string } | { type : 'b' , baz : string } > > ( )
20
21
expectTypeOf ( $fetch ( '/api/other' ) ) . toEqualTypeOf < Promise < unknown > > ( )
21
22
expectTypeOf ( $fetch < TestResponse > ( '/test' ) ) . toEqualTypeOf < Promise < TestResponse > > ( )
22
23
} )
@@ -25,6 +26,8 @@ describe('API routes', () => {
25
26
expectTypeOf ( useAsyncData ( 'api-hello' , ( ) => $fetch ( '/api/hello' ) ) . data ) . toEqualTypeOf < Ref < string | null > > ( )
26
27
expectTypeOf ( useAsyncData ( 'api-hey' , ( ) => $fetch ( '/api/hey' ) ) . data ) . toEqualTypeOf < Ref < { foo : string , baz : string } | null > > ( )
27
28
expectTypeOf ( useAsyncData ( 'api-hey-with-pick' , ( ) => $fetch ( '/api/hey' ) , { pick : [ 'baz' ] } ) . data ) . toEqualTypeOf < Ref < { baz : string } | null > > ( )
29
+ expectTypeOf ( useAsyncData ( 'api-union' , ( ) => $fetch ( '/api/union' ) ) . data ) . toEqualTypeOf < Ref < { type : 'a' , foo : string } | { type : 'b' , baz : string } | null > > ( )
30
+ expectTypeOf ( useAsyncData ( 'api-union-with-pick' , ( ) => $fetch ( '/api/union' ) , { pick : [ 'type' ] } ) . data ) . toEqualTypeOf < Ref < { type : 'a' } | { type : 'b' } | null > > ( )
28
31
expectTypeOf ( useAsyncData ( 'api-other' , ( ) => $fetch ( '/api/other' ) ) . data ) . toEqualTypeOf < Ref < unknown > > ( )
29
32
expectTypeOf ( useAsyncData < TestResponse > ( 'api-generics' , ( ) => $fetch ( '/test' ) ) . data ) . toEqualTypeOf < Ref < TestResponse | null > > ( )
30
33
@@ -34,6 +37,8 @@ describe('API routes', () => {
34
37
expectTypeOf ( useLazyAsyncData ( 'lazy-api-hello' , ( ) => $fetch ( '/api/hello' ) ) . data ) . toEqualTypeOf < Ref < string | null > > ( )
35
38
expectTypeOf ( useLazyAsyncData ( 'lazy-api-hey' , ( ) => $fetch ( '/api/hey' ) ) . data ) . toEqualTypeOf < Ref < { foo : string , baz : string } | null > > ( )
36
39
expectTypeOf ( useLazyAsyncData ( 'lazy-api-hey-with-pick' , ( ) => $fetch ( '/api/hey' ) , { pick : [ 'baz' ] } ) . data ) . toEqualTypeOf < Ref < { baz : string } | null > > ( )
40
+ expectTypeOf ( useLazyAsyncData ( 'lazy-api-union' , ( ) => $fetch ( '/api/union' ) ) . data ) . toEqualTypeOf < Ref < { type : 'a' , foo : string } | { type : 'b' , baz : string } | null > > ( )
41
+ expectTypeOf ( useLazyAsyncData ( 'lazy-api-union-with-pick' , ( ) => $fetch ( '/api/union' ) , { pick : [ 'type' ] } ) . data ) . toEqualTypeOf < Ref < { type : 'a' } | { type : 'b' } | null > > ( )
37
42
expectTypeOf ( useLazyAsyncData ( 'lazy-api-other' , ( ) => $fetch ( '/api/other' ) ) . data ) . toEqualTypeOf < Ref < unknown > > ( )
38
43
expectTypeOf ( useLazyAsyncData < TestResponse > ( 'lazy-api-generics' , ( ) => $fetch ( '/test' ) ) . data ) . toEqualTypeOf < Ref < TestResponse | null > > ( )
39
44
@@ -45,6 +50,8 @@ describe('API routes', () => {
45
50
expectTypeOf ( useFetch ( '/api/hello' ) . data ) . toEqualTypeOf < Ref < string | null > > ( )
46
51
expectTypeOf ( useFetch ( '/api/hey' ) . data ) . toEqualTypeOf < Ref < { foo : string , baz : string } | null > > ( )
47
52
expectTypeOf ( useFetch ( '/api/hey' , { pick : [ 'baz' ] } ) . data ) . toEqualTypeOf < Ref < { baz : string } | null > > ( )
53
+ expectTypeOf ( useFetch ( '/api/union' ) . data ) . toEqualTypeOf < Ref < { type : 'a' , foo : string } | { type : 'b' , baz : string } | null > > ( )
54
+ expectTypeOf ( useFetch ( '/api/union' , { pick : [ 'type' ] } ) . data ) . toEqualTypeOf < Ref < { type : 'a' } | { type : 'b' } | null > > ( )
48
55
expectTypeOf ( useFetch ( '/api/other' ) . data ) . toEqualTypeOf < Ref < unknown > > ( )
49
56
expectTypeOf ( useFetch < TestResponse > ( '/test' ) . data ) . toEqualTypeOf < Ref < TestResponse | null > > ( )
50
57
@@ -54,7 +61,8 @@ describe('API routes', () => {
54
61
expectTypeOf ( useLazyFetch ( '/api/hello' ) . data ) . toEqualTypeOf < Ref < string | null > > ( )
55
62
expectTypeOf ( useLazyFetch ( '/api/hey' ) . data ) . toEqualTypeOf < Ref < { foo : string , baz : string } | null > > ( )
56
63
expectTypeOf ( useLazyFetch ( '/api/hey' , { pick : [ 'baz' ] } ) . data ) . toEqualTypeOf < Ref < { baz : string } | null > > ( )
57
- expectTypeOf ( useLazyFetch ( '/api/other' ) . data ) . toEqualTypeOf < Ref < unknown > > ( )
64
+ expectTypeOf ( useLazyFetch ( '/api/union' ) . data ) . toEqualTypeOf < Ref < { type : 'a' , foo : string } | { type : 'b' , baz : string } | null > > ( )
65
+ expectTypeOf ( useLazyFetch ( '/api/union' , { pick : [ 'type' ] } ) . data ) . toEqualTypeOf < Ref < { type : 'a' } | { type : 'b' } | null > > ( )
58
66
expectTypeOf ( useLazyFetch ( '/api/other' ) . data ) . toEqualTypeOf < Ref < unknown > > ( )
59
67
expectTypeOf ( useLazyFetch < TestResponse > ( '/test' ) . data ) . toEqualTypeOf < Ref < TestResponse | null > > ( )
60
68
0 commit comments