|
| 1 | +import type { components, paths } from './api/index.js'; |
| 2 | +import { requestFn } from '@openapi-qraft/react'; |
| 3 | +import * as callbacksIndex from '@openapi-qraft/react/callbacks'; |
| 4 | +import * as callbacks from '@openapi-qraft/react/callbacks/index'; |
| 5 | +import { useMutation } from '@openapi-qraft/react/callbacks/useMutation'; |
| 6 | +import { useQuery } from '@openapi-qraft/react/callbacks/useQuery'; |
| 7 | +import { |
| 8 | + createSecureRequestFn, |
| 9 | + QraftSecureRequestFn, |
| 10 | +} from '@openapi-qraft/react/Unstable_QraftSecureRequestFn'; |
| 11 | +import { QueryClient } from '@tanstack/react-query'; |
| 12 | +import { createAPIClient as createAPIClientMjs } from './api/index.js'; |
| 13 | + |
| 14 | +console.log({} satisfies Partial<components>); |
| 15 | +console.log({} satisfies Partial<paths>); |
| 16 | + |
| 17 | +if (typeof createAPIClientMjs !== 'undefined') { |
| 18 | + console.log('Client is imported successfully from esm project.'); |
| 19 | +} else { |
| 20 | + console.error('Client is not imported from esm project.'); |
| 21 | + process.exit(1); |
| 22 | +} |
| 23 | + |
| 24 | +if (typeof callbacks !== 'undefined') { |
| 25 | + console.log('Callbacks are imported successfully from esm project.'); |
| 26 | +} else { |
| 27 | + console.error('Callbacks are not imported from esm project.'); |
| 28 | + process.exit(1); |
| 29 | +} |
| 30 | + |
| 31 | +if (typeof callbacksIndex !== 'undefined') { |
| 32 | + console.log('Callbacks index is imported successfully from esm project.'); |
| 33 | +} else { |
| 34 | + console.error('Callbacks index is not imported from esm project.'); |
| 35 | + process.exit(1); |
| 36 | +} |
| 37 | + |
| 38 | +if (typeof useMutation !== 'undefined') { |
| 39 | + console.log('useMutation is imported successfully from esm project.'); |
| 40 | +} else { |
| 41 | + console.error('useMutation is not imported from esm project.'); |
| 42 | + process.exit(1); |
| 43 | +} |
| 44 | + |
| 45 | +if (typeof useQuery !== 'undefined') { |
| 46 | + console.log('useQuery is imported successfully from esm project.'); |
| 47 | +} else { |
| 48 | + console.error('useQuery is not imported from esm project.'); |
| 49 | + process.exit(1); |
| 50 | +} |
| 51 | + |
| 52 | +if (typeof createSecureRequestFn !== 'undefined') { |
| 53 | + console.log( |
| 54 | + 'createSecureRequestFn is imported successfully from esm project.' |
| 55 | + ); |
| 56 | +} else { |
| 57 | + console.error('createSecureRequestFn is not imported from esm project.'); |
| 58 | + process.exit(1); |
| 59 | +} |
| 60 | + |
| 61 | +if (typeof QraftSecureRequestFn !== 'undefined') { |
| 62 | + console.log( |
| 63 | + 'QraftSecureRequestFn is imported successfully from esm project.' |
| 64 | + ); |
| 65 | +} else { |
| 66 | + console.error('QraftSecureRequestFn is not imported from esm project.'); |
| 67 | + process.exit(1); |
| 68 | +} |
| 69 | + |
| 70 | +function useTsCheck() { |
| 71 | + const client = createAPIClientMjs({ |
| 72 | + baseUrl: 'https://api.example.com', |
| 73 | + queryClient: new QueryClient(), |
| 74 | + requestFn, |
| 75 | + }); |
| 76 | + |
| 77 | + const query = client.pet.findPetsByStatus.useSuspenseInfiniteQuery( |
| 78 | + {}, |
| 79 | + { |
| 80 | + initialPageParam: { |
| 81 | + query: { |
| 82 | + status: 'sold', |
| 83 | + }, |
| 84 | + }, |
| 85 | + getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => { |
| 86 | + // @ts-expect-error - should not be never or any |
| 87 | + lastPageParam.query?.status satisfies never; |
| 88 | + lastPageParam.query?.status satisfies |
| 89 | + | undefined |
| 90 | + | 'sold' |
| 91 | + | 'available' |
| 92 | + | 'pending'; |
| 93 | + |
| 94 | + return lastPageParam.query?.status === 'sold' |
| 95 | + ? { |
| 96 | + query: { |
| 97 | + status: 'sold', |
| 98 | + }, |
| 99 | + } |
| 100 | + : undefined; |
| 101 | + }, |
| 102 | + } |
| 103 | + ); |
| 104 | + |
| 105 | + query.data.pages[0] satisfies typeof client.pet.findPetsByStatus.types.data; |
| 106 | + // @ts-expect-error - should not be never or any |
| 107 | + query.data.pages[0] satisfies never; |
| 108 | +} |
0 commit comments