Charlie Lamb
Explore posts from serversHono RPC TypeScript error
Hey I'm getting a really frusttrating error where TypeScript is not inferring types in a monorepo. I'm building a monorepo using Nextjs for the frontend and bun & hono for the backend. I'm trying to use hono rpc and I'm exporting the type of my router like this in my app.ts file in my backend project:
import createApp from '@/lib/create-app'
import configureOpenAPI from '@/lib/configure-open-api'
import index from '@/routes/index.route'
import users from '@/routes/user/user.index'
import connects from '@/routes/connects/connects.index'
const app = createApp()
const routes = [index, users, connects] as const
configureOpenAPI(app)
routes.forEach((route) => {
app.route('/', route)
})
export default app
export type AppType = (typeof routes)[number]
and then trying to import it in my frontend project in my client.ts file
import type { AppType } from '../backend/src/app'
import { hc } from 'hono/client'
const client = hc<AppType>('http://localhost:8000')
export default client
This isn't working and my Type is being inferred as any. When I hover over app type in app.ts in my backend - I see this type
type AppType = OpenAPIHono<AppBindings, {
"/": {
$get: {
input: {};
output: {
message: string;
};
outputFormat: "json" | "text";
status: 200;
};
};
}, "/"> | OpenAPIHono<AppBindings, {
...;
}, "/"> | OpenAPIHono<...>
It 100% has the right type.
When I hover over AppType in client.ts however I see this:
(alias) type AppType = any
import AppType
Anyone know how I can fix this issue?
Repo to see for yourself + all tsconfigs: https://github.com/charlietlamb/postpad
Thanks for all help 🙂
5 replies
DTDrizzle Team
•Created by Charlie Lamb on 8/22/2024 in #help
Can't run drizzle studio
Hey I'm using the t4 starter monorepo and am trying to run drizzle studio however its not working. I get this error: Error: Cannot find module '@drizzle-team/studio/server'
These are the terminal logs:
bun studio
$ cd packages/api && bun studio
$ drizzle-kit studio
node:internal/modules/cjs/loader:1146
throw err;
^
Error: Cannot find module '@drizzle-team/studio/server'
Package.json:
{
"name": "@t4/api",
"version": "2.0.0",
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"dev": "wrangler dev",
"generate": "drizzle-kit generate:sqlite --schema=./src/db/schema.ts --out=./migrations",
"migrate": "wrangler d1 migrations apply production",
"migrate:local": "wrangler d1 migrations apply production --local",
"seed": "wrangler d1 execute production --file=./seed/seed.sql",
"seed:local": "wrangler d1 execute production --local --file=./seed/seed.sql",
"studio": "drizzle-kit studio",
"deploy": "wrangler deploy --minify src/worker.ts",
"postinstall": "bun generate",
"clean": "rm -rf .turbo node_modules"
},
"dependencies": {
"@hono/trpc-server": "^0.1.0",
"@trpc/server": "^10.43.2",
"@tsndr/cloudflare-worker-jwt": "2.2.7",
"drizzle-orm": "^0.29.0",
"drizzle-valibot": "beta",
"hono": "^3.9.2",
"miniflare": "3.20231025.1",
"superjson": "1.13.3",
"valibot": "^0.20.1",
"pg": "^8.12.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231025.0",
"drizzle-kit": "^0.24.1",
"typescript": "^5.2.2",
"wrangler": "3.22.3"
}
}
Tried installing postgres as I saw this solution online but hasn't changed anything.
13 replies