Currently getting started with Hono using the Bun runtime. Their Hello World script is below:
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => c.text('Hello Bun!'))
export default app
The above code works without an issue.
However, I need to make a small change to the code by rewriting the arrow function (to non-arrow syntax). Ergo, I updated the script to look like this:
...
app.get('/', function(c) {
c.text('Hello Bun!'));
});
...
The problem is that now I get an error in VS Code – a squiggly under function
– saying:
No overload matches this call.
The last overload gave the following error.
Argument of type '(c: Context<BlankEnv, "/", BlankInput>) => void' is not assignable to parameter of type 'H<BlankEnv, "/", BlankInput, HandlerResponse<any>>'.
Type '(c: Context<BlankEnv, "/", BlankInput>) => void' is not assignable to type 'MiddlewareHandler<BlankEnv, "/", BlankInput>'.
Type 'void' is not assignable to type 'Promise<void | Response>'.ts(2769)
types.d.ts(162, 5): The last overload is declared here.
(local function)(c: Context<BlankEnv, "/", BlankInput>): void
After fiddling around a bit, I updated the code to look like this:
...
app.get('/', function(c: any): any {
c.text('Hello Bun!'));
});
...
The error is no longer there, but the script shows a 404 Not Found
error when I run it. I do not fully understand why as my current grasp of TypeScript (especially generics) is not strong enough to resolve this.
Can you show how to properly rewrite arrow functions in TypeScript to non-arrow functions, and also explain (if possible) why the error appeared?
2