Skip to content

Commit

Permalink
type fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Dec 29, 2024
1 parent cf93dd0 commit 946e2a5
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion apps/content/examples/react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import type { RouterClient } from '@orpc/server'
import type { router } from 'examples/server'
import { createORPCReactQueryUtils } from '@orpc/react-query'

export const orpc = createORPCReactQueryUtils({} as RouterClient<typeof router /** or contract router */>)
export const orpc = createORPCReactQueryUtils({} as RouterClient<typeof router /** or contract router */, unknown>)
2 changes: 1 addition & 1 deletion apps/content/examples/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import type { RouterClient } from '@orpc/server'
import type { router } from 'examples/server'
import { createORPCReact } from '@orpc/react'

export const { orpc, ORPCContext } = createORPCReact<RouterClient<typeof router /** or contract router */>>()
export const { orpc, ORPCContext } = createORPCReact<RouterClient<typeof router /** or contract router */, unknown>>()
2 changes: 1 addition & 1 deletion apps/content/examples/vue-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import type { RouterClient } from '@orpc/server'
import type { router } from 'examples/server'
import { createORPCVueQueryUtils } from '@orpc/vue-query'

export const orpc = createORPCVueQueryUtils({} as RouterClient<typeof router /** or contract router */>)
export const orpc = createORPCVueQueryUtils({} as RouterClient<typeof router /** or contract router */, unknown>)
13 changes: 8 additions & 5 deletions packages/client/tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { os } from '@orpc/server'
import { ORPCHandler } from '@orpc/server/fetch'
import { z } from 'zod'
import { createORPCFetchClient } from '../src'
import { createClient } from '../src'
import { ORPCLink } from '../src/adapters/fetch'

export const orpcServer = os

Expand Down Expand Up @@ -98,13 +99,15 @@ export const appRouter = orpcServer.router({

const orpcHandler = new ORPCHandler(appRouter)

export const client = createORPCFetchClient<typeof appRouter>({
baseURL: 'http://localhost:3000',
const orpcLink = new ORPCLink({
url: 'http://localhost:3000',

async fetch(...args) {
async fetch(input, init) {
await new Promise(resolve => setTimeout(resolve, 100))
const request = new Request(...args)
const request = new Request(input, init)

return orpcHandler.fetch(request)
},
})

export const client = createClient<typeof appRouter>(orpcLink)
5 changes: 3 additions & 2 deletions packages/next/src/action-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export type SafeAction<TInput, TOutput,
> = ProcedureClient<
TInput,
| [TOutput, undefined, 'success']
| [undefined, WELL_ORPC_ERROR_JSON, 'error']
| [undefined, WELL_ORPC_ERROR_JSON, 'error'],
unknown
>

export function createSafeAction<
Expand All @@ -21,7 +22,7 @@ export function createSafeAction<

const safeAction: SafeAction<SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, TFuncOutput>> = async (...[input, option]) => {
try {
const output = await caller(input as any, option)
const output = await caller(input as any, option as any)
return [output as any, undefined, 'success']
}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/action-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type UseActionState<TInput, TOutput> = {
const idleState = { status: 'idle', isPending: false, isError: false, input: undefined, output: undefined, error: undefined } as const

export function useAction<TInput, TOutput>(
action: ProcedureClient<TInput, TOutput>,
action: ProcedureClient<TInput, TOutput, any>,
hooks?: Hooks<TInput, TOutput, undefined, undefined>,
): UseActionState<TInput, TOutput> {
const [state, setState] = useState<Omit<UseActionState<TInput, TOutput>, 'execute' | 'reset'>>(idleState)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/action-safe-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useSafeAction<TInput, TOutput>(
action: SafeAction<TInput, TOutput>,
hooks?: Hooks<TInput, TOutput, undefined, undefined>,
): UseActionState<TInput, TOutput> {
const normal: ProcedureClient<TInput, TOutput> = useCallback(async (...args) => {
const normal: ProcedureClient<TInput, TOutput, unknown> = useCallback(async (...args) => {
const [output, errorJson, status] = await action(...args)

if (status === 'error') {
Expand Down
17 changes: 10 additions & 7 deletions packages/react/tests/orpc.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable react/no-context-provider */
import type { RouterClient } from '@orpc/server'
import { createORPCFetchClient } from '@orpc/client'
import { createClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'
import { os } from '@orpc/server'
import { ORPCHandler } from '@orpc/server/fetch'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
Expand Down Expand Up @@ -95,18 +97,19 @@ export const appRouter = orpcServer.router({

const orpcHandler = new ORPCHandler(appRouter)

export const orpcClient = createORPCFetchClient<typeof appRouter>({
baseURL: 'http://localhost:3000',

async fetch(...args) {
const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
async fetch(input, init) {
await new Promise(resolve => setTimeout(resolve, 100))
const request = new Request(...args)
const request = new Request(input, init)

return orpcHandler.fetch(request)
},
})

export const { orpc, ORPCContext } = createORPCReact<RouterClient<typeof appRouter>>()
export const orpcClient = createClient<typeof appRouter>(orpcLink)

export const { orpc, ORPCContext } = createORPCReact<RouterClient<typeof appRouter, unknown>>()

export const queryClient = new QueryClient({
defaultOptions: {
Expand Down
10 changes: 5 additions & 5 deletions packages/server/src/lazy-decorated.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('DecoratedLazy', () => {
expectTypeOf(decorated).toMatchTypeOf<Lazy<ANY_PROCEDURE>>()

expectTypeOf(decorated).toMatchTypeOf<
ProcedureClient<unknown, { val: number }>
ProcedureClient<unknown, { val: number }, unknown>
>()
})

Expand All @@ -53,19 +53,19 @@ describe('DecoratedLazy', () => {
expectTypeOf({ router: decorated }).toMatchTypeOf<ANY_ROUTER>()

expectTypeOf(decorated.ping).toMatchTypeOf<Lazy<ANY_PROCEDURE>>()
expectTypeOf(decorated.ping).toMatchTypeOf <ProcedureClient<unknown, { val: number }>>()
expectTypeOf(decorated.ping).toMatchTypeOf<ProcedureClient<unknown, { val: number }, unknown>>()

expectTypeOf(decorated.pong).toMatchTypeOf<Lazy<ANY_PROCEDURE>>()
expectTypeOf(decorated.pong).toMatchTypeOf<ProcedureClient<{ val: string }, unknown>>()
expectTypeOf(decorated.pong).toMatchTypeOf<ProcedureClient<{ val: string }, unknown, unknown>>()

expectTypeOf(decorated.nested).toMatchTypeOf<Lazy<ANY_ROUTER>>()
expectTypeOf({ router: decorated.nested }).toMatchTypeOf<ANY_ROUTER>()

expectTypeOf(decorated.nested.ping).toMatchTypeOf<Lazy<ANY_PROCEDURE>>()
expectTypeOf(decorated.nested.ping).toMatchTypeOf<ProcedureClient<unknown, { val: number }>>()
expectTypeOf(decorated.nested.ping).toMatchTypeOf<ProcedureClient<unknown, { val: number }, unknown>>()

expectTypeOf(decorated.nested.pong).toMatchTypeOf<Lazy<ANY_PROCEDURE>>()
expectTypeOf(decorated.nested.pong).toMatchTypeOf<ProcedureClient<{ val: string }, unknown>>()
expectTypeOf(decorated.nested.pong).toMatchTypeOf<ProcedureClient<{ val: string }, unknown, unknown>>()
})

it('flat lazy', () => {
Expand Down
9 changes: 6 additions & 3 deletions playgrounds/contract-openapi/src/playground-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
*/

import type { contract } from './contract'
import { createORPCFetchClient } from '@orpc/client'
import { createClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpc = createORPCFetchClient<typeof contract>({
baseURL: 'http://localhost:3000/api',
const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
})

const orpc = createClient<typeof contract>(orpcLink)

const planets = await orpc.planet.list({})

const planet = await orpc.planet.find({ id: 1 })
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/contract-openapi/src/playground-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RouterClient } from '@orpc/server'
import type { contract } from './contract'
import { createORPCReact } from '@orpc/react'

const { orpc } = createORPCReact<RouterClient<typeof contract>>()
const { orpc } = createORPCReact<RouterClient<typeof contract, unknown>>()

const listQuery = orpc.planet.list.useInfiniteQuery({
input: {},
Expand Down
9 changes: 6 additions & 3 deletions playgrounds/expressjs/src/playground-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
*/

import type { router } from './router'
import { createORPCFetchClient } from '@orpc/client'
import { createClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpc = createORPCFetchClient<typeof router>({
baseURL: 'http://localhost:3000/api',
const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
})

const orpc = createClient<typeof router>(orpcLink)

const planets = await orpc.planet.list({})

const planet = await orpc.planet.find({ id: 1 })
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/expressjs/src/playground-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RouterClient } from '@orpc/server'
import type { router } from './router'
import { createORPCReact } from '@orpc/react'

const { orpc } = createORPCReact <RouterClient<typeof router>>()
const { orpc } = createORPCReact<RouterClient<typeof router, unknown>>()

const listQuery = orpc.planet.list.useInfiniteQuery({
input: {},
Expand Down
9 changes: 6 additions & 3 deletions playgrounds/openapi/src/playground-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
*/

import type { router } from './router'
import { createORPCFetchClient } from '@orpc/client'
import { createClient } from '@orpc/client'
import { ORPCLink } from '@orpc/client/fetch'

const orpc = createORPCFetchClient<typeof router>({
baseURL: 'http://localhost:3000/api',
const orpcLink = new ORPCLink({
url: 'http://localhost:3000/api',
})

const orpc = createClient<typeof router>(orpcLink)

const planets = await orpc.planet.list({})

const planet = await orpc.planet.find({ id: 1 })
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/openapi/src/playground-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RouterClient } from '@orpc/server'
import type { router } from './router'
import { createORPCReact } from '@orpc/react'

const { orpc } = createORPCReact <RouterClient<typeof router>>()
const { orpc } = createORPCReact <RouterClient<typeof router, unknown>>()

const listQuery = orpc.planet.list.useInfiniteQuery({
input: {},
Expand Down

0 comments on commit 946e2a5

Please sign in to comment.