Skip to content

Commit a85bfde

Browse files
committed
Use SeamHttpEndpointQueryPaths
1 parent df9d475 commit a85bfde

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"@rxfork/r2wc-react-to-web-component": "^2.4.0",
146146
"@seamapi/fake-devicedb": "^1.6.1",
147147
"@seamapi/fake-seam-connect": "^1.76.0",
148-
"@seamapi/http": "^1.38.0",
148+
"@seamapi/http": "^1.38.1",
149149
"@seamapi/types": "^1.395.3",
150150
"@storybook/addon-designs": "^7.0.1",
151151
"@storybook/addon-essentials": "^7.0.2",

src/lib/seam/use-seam-query.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import type {
22
SeamHttpApiError,
3-
SeamHttpEndpointPaths,
3+
SeamHttpEndpointQueryPaths,
44
SeamHttpEndpoints,
55
} from '@seamapi/http/connect'
66
import { useQuery, type UseQueryResult } from '@tanstack/react-query'
77

88
import { useSeamClient } from 'lib/seam/use-seam-client.js'
99

10-
type Endpoints = Pick<SeamHttpEndpoints, SeamHttpEndpointPaths>
11-
12-
export function useSeamQuery<T extends keyof Endpoints>(
10+
export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
1311
endpointPath: T,
14-
params?: Parameters<Endpoints[T]>[0],
15-
options?: Parameters<Endpoints[T]>[1]
16-
): UseQueryResult<Awaited<ReturnType<Endpoints[T]>>, SeamHttpApiError> {
12+
params?: Parameters<SeamHttpEndpoints[T]>[0],
13+
options?: Parameters<SeamHttpEndpoints[T]>[1]
14+
): UseQueryResult<Awaited<ReturnType<SeamHttpEndpoints[T]>>, SeamHttpApiError> {
1715
const { endpointClient: client } = useSeamClient()
1816
return useQuery({
1917
enabled: client != null,
2018
queryKey: [endpointPath, params],
2119
queryFn: async () => {
2220
if (client == null) return null
23-
const endpoint = client[endpointPath] as Endpoints[T]
24-
// @ts-expect-error: The types are correct at runtime, but TypeScript can't infer the specific endpoint types
21+
// Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
22+
// Type assertion is needed here for performance reasons. The types are correct at runtime.
23+
const endpoint = client[endpointPath] as any
2524
return await endpoint(params, options)
2625
},
2726
})

0 commit comments

Comments
 (0)