first question here.
Does anyone know how to extend the response in Opine (Deno framework) so that I can create custom responses?
For example I would like to create:
res.success(message)
So that I don't need to set HTTP codes every time like this:
res.setStatus(200).json({data: "success" });
I tried extending the response like it's done here: https://deno.land/x/opine@2.1.5/test/units/app.response.test.ts
This is my code:
import { opine } from "https://deno.land/x/opine@2.1.4/mod.ts";
const app = opine();
(app.response as any).shout = function (str: string) {
this.send(str.toUpperCase());
};
app.get("/", (req, res) => {
res.shout("hello")
})
app.listen(3000);
console.log("Opine started on port 3000");
export { app };
But when I run the program I get:
error: TS2339 [ERROR]: Property 'shout' does not exist on type 'OpineResponse<any>'.
res.shout("hello")
~~~~~
Thank you.