This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type R = Record<string, string>; | |
| export type PageProps< | |
| PathParams extends R | undefined = undefined, | |
| SearchParams extends R | undefined = undefined, | |
| > = { | |
| params: PathParams extends R ? PathParams : never; | |
| searchParams: SearchParams extends R | |
| ? Partial<{ | |
| [K in keyof SearchParams]: string | string[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { type userRouter } from "@/server/api/routers/user.router"; | |
| import { createTRPCReact } from "@trpc/react-query"; | |
| import { type AnyTRPCRouter } from "@trpc/server"; | |
| // create-api.ts | |
| export const createApi = <TRouter extends AnyTRPCRouter>(root: string) => { | |
| const router = createTRPCReact<TRouter>(); | |
| // Access the proxy already so we dont have to repeat ourselves e.g. `userApi.user.accounts...` | |
| return (router as any)[root] as Omit< |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const safeTry = async <T>( | |
| promise: Promise<T> | |
| ): Promise<[T, null] | [null, Error]> => { | |
| try { | |
| const data = await promise; | |
| return [data, null]; | |
| } catch (throwable) { | |
| if (throwable instanceof Error) return [null, throwable]; | |
| throw throwable; | |
| } |