honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
421 stars 145 forks source link

[TRPC-SERVER] typescript error for router property #220

Closed programmer106 closed 2 months ago

programmer106 commented 11 months ago

by adding the line in main.ts:

app.use('/trpc/*', trpcServer({
  router: router,
}))

Got such an error for router prop:

Type 'CreateRouterInner<RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { hello: BuildProcedure<...>; s3: CreateRouterInner<...>; }>' is not assignable to type 'AnyRouter'.
  The types returned by 'createCaller(...)' are incompatible between these types.
    Type 'DecoratedProcedureRecord<{ hello: BuildProcedure<"query", { _config: RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>; ... 5 more ...; _output_out: unique symbol; }, string>; s3: CreateRouterInner<...>; }> & { ...; }' is not assignable to type 'DecoratedProcedureRecord<any> & { query: inferHandlerFn<any>; mutation: inferHandlerFn<any>; subscription: inferHandlerFn<any>; }'.
      Type 'DecoratedProcedureRecord<{ hello: BuildProcedure<"query", { _config: RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>; ... 5 more ...; _output_out: unique symbol; }, string>; s3: CreateRouterInner<...>; }> & { ...; }' is not assignable to type 'DecoratedProcedureRecord<any>'.
        Property 'query' is incompatible with index signature.
          Type 'inferHandlerFn<{}>' is not assignable to type 'DecoratedProcedureRecord<any> | DecorateProcedure<any>'.
            Type 'inferHandlerFn<{}>' is not assignable to type 'DecorateProcedure<any>'.
              Types of parameters 'path' and 'input' are incompatible.
                Type 'any' is not assignable to type 'never'.ts(2322)
types.d.ts(13, 5): The expected type comes from property 'router' which is declared here on type 'tRPCOptions'
(property) router: AnyRouter

"@hono/trpc-server": "^0.1.0", "@trpc/server": "^10.40.0", bun 1.0.7

Boscop commented 7 months ago

I'm getting the same.

Type 'CreateRouterInner<RootConfig<{ ctx: ApiContextProps; meta: object; errorShape: DefaultErrorShape; transformer: typeof SuperJSON; }>, { hello: CreateRouterInner<...>; user: CreateRouterInner<...>; auth: CreateRouterInner<...>; car: CreateRouterInner<...>; headlines: CreateRouterInner<...>; }>' is not assignable to type 'AnyRouter'.
  The types returned by 'createCaller(...)' are incompatible between these types.
    Type 'DecoratedProcedureRecord<{ hello: CreateRouterInner<RootConfig<{ ctx: ApiContextProps; meta: object; errorShape: DefaultErrorShape; transformer: typeof SuperJSON; }>, { ...; }>; user: CreateRouterInner<...>; auth: CreateRouterInner<...>; car: CreateRouterInner<...>; headlines: CreateRouterInner<...>; }> & { ...; }' is not assignable to type 'DecoratedProcedureRecord<any> & { query: inferHandlerFn<any>; mutation: inferHandlerFn<any>; subscription: inferHandlerFn<any>; }'.
      Type 'DecoratedProcedureRecord<{ hello: CreateRouterInner<RootConfig<{ ctx: ApiContextProps; meta: object; errorShape: DefaultErrorShape; transformer: typeof SuperJSON; }>, { ...; }>; user: CreateRouterInner<...>; auth: CreateRouterInner<...>; car: CreateRouterInner<...>; headlines: CreateRouterInner<...>; }> & { ...; }' is not assignable to type 'DecoratedProcedureRecord<any>'.
        Property 'query' is incompatible with index signature.
          Type 'inferHandlerFn<{}>' is not assignable to type 'DecoratedProcedureRecord<any> | DecorateProcedure<any>'.
            Type 'inferHandlerFn<{}>' is not assignable to type 'DecorateProcedure<any>'.
              Types of parameters 'path' and 'input' are incompatible.
                Type 'any' is not assignable to type 'never'.ts(2322)
types.d.ts(13, 5): The expected type comes from property 'router' which is declared here on type 'tRPCOptions'

With these:

    "hono": "^3.9.2",
    "@hono/trpc-server": "^0.1.0",
    "@trpc/server": "^10.45.1",

bun 1.0.11

@programmer106 Did you find out why this happens? :)

MeatBoyed commented 3 months ago

I'm not sure if the error I'm getting is exactly the same, but it looks similar....

Error: `.next/types/app/api/[[...route]]/route.ts:8:13 Type error: Type 'OmitWithTag<typeof import("C:/Users/Charl/Code/Hacienda-X/main-app/app/api/[[...route]]/route"), "POST" | "GET" | "runtime" | "config" | "generateStaticParams" | "revalidate" | "dynamic" | ... 8 more ... | "PATCH", "">' does not satisfy the constraint '{ [x: string]: never; }'. Property 'honoClient' is incompatible with index signature. Type '{ properties: ClientRequest<{ $get: { input: {}; output: { Address: { address_id: string; address: string; latitude: number; longitude: number; property_id: string; } | null; property_id: string; agent_id: string; ... 13 more ...; updatedAt: string; }[]; outputFormat: "json"; status: StatusCode; }; }>; } & ... 4 mor...' is not assignable to type 'never'.

6 | 7 | // Check that the entry is a valid entry

8 | checkFields<Diff<{ | ^ 9 | GET?: Function 10 | HEAD?: Function 11 | OPTIONS?: Function  ELIFECYCLE  Command failed with exit code 1.`

Package versions: "hono": "^4.3.4", "@hono-storage/s3": "^0.0.11", "@hono/clerk-auth": "^2.0.0", "@hono/zod-validator": "^0.2.1",

yusukebe commented 2 months ago

This issue may be solved in the latest versions. So, I am closing this issue now.

@MeatBoyed If you still have a problem, please create a new issue with the link to the minimal project to reproduce the bug.