H
Hono•3w ago
Nivek

Bun Monorepo Hono RPC

I'm trying to setup hono rpc, but I'm not able to get the types or autocompletion for it. I did check to make sure the compiler options are set to strict: true but doesn't seem to work. If you don't mind checking https://github.com/nikevsoft/bun-monorepo what I'm doing wrong?
GitHub
GitHub - nikevsoft/bun-monorepo
Contribute to nikevsoft/bun-monorepo development by creating an account on GitHub.
11 Replies
Shy
Shy•3w ago
try chaining like this
const app = new Hono()
.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});
const app = new Hono()
.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});
Nivek
Nivek•3w ago
i gave that a try, it didn't work as well 😦
Shy
Shy•3w ago
I'll clone it and try it did work for me? I cloned and installed then only changed this
Shy
Shy•3w ago
No description
Shy
Shy•3w ago
No description
Shy
Shy•3w ago
No description
Shy
Shy•3w ago
this is the server index
import { Hono } from "hono";

const app = new Hono()
.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});

export type AppType = typeof app;
export default app;
import { Hono } from "hono";

const app = new Hono()
.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});

export type AppType = typeof app;
export default app;
Nivek
Nivek•3w ago
hmm that's so odd mine just doesn't work. I even tried in github codespaces and also got the same issue.
No description
Shy
Shy•3w ago
you're not doing correct
import { Hono } from "hono";

const app = new Hono();

app.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});

export type AppType = typeof app;
export default app;
import { Hono } from "hono";

const app = new Hono();

app.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});

export type AppType = typeof app;
export default app;
you're doing this but you should do this
import { Hono } from "hono";

const app = new Hono()
.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});

export type AppType = typeof app;
export default app;
import { Hono } from "hono";

const app = new Hono()
.get("/", (c) => {
return c.text("Hello Hono!");
})
.basePath("api").get("/expenses", (c) => {
return c.json({
total: 13034.12,
});
});

export type AppType = typeof app;
export default app;
Nivek
Nivek•3w ago
oh man, thank you!! I didn't think that would make a difference. Do you know why you cant do it the other way? Thank you @Shy !
Shy
Shy•3w ago
Honestly my brain just became typescripty…? I can’t exactly understand why but even from the first day I saw it I knew it will probably not work 😅 But anyways looking at the typescript docs https://www.typescriptlang.org/docs/handbook/type-inference.html type inference happens when initializing the variables That’s why hono suggests always doing this practice https://hono.dev/docs/guides/rpc#using-rpc-with-larger-applications
Documentation - Type Inference
How code flow analysis works in TypeScript
RPC - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Want results from more Discord servers?
Add your server