Open bogeychan opened 3 months ago
{ "@elysiajs/eden": "^1.0.14", "@elysiajs/swagger": "^1.0.5", "elysia": "^1.0.22" }
import { treaty } from "@elysiajs/eden"; import { swagger } from "@elysiajs/swagger"; import { Elysia, t } from "elysia"; const app = new Elysia() .use(swagger()) .guard( { response: { 418: t.Union([t.Literal("foo"), t.Literal("bar")]), }, }, (app) => app .onBeforeHandle(async ({ set }) => { if (Math.random() > 0.5) { set.status = 418; return "foo"; } }) .onBeforeHandle(async ({ set }) => { if (Math.random() > 0.5) { set.status = 418; return "bar"; } }) .get("/test", () => 1, { response: { 200: t.Number(), }, }) ) .listen(8080); const client = treaty<typeof app>(app.server!.url.toString()); const { error } = await client.test.get(); if (error) { type Err = typeof error; // <--- }
Err has type {status: unknown, value: unknown} instead of {status: 418, value: "foo" | "bar"}
Err
{status: unknown, value: unknown}
{status: 418, value: "foo" | "bar"}
adding type to handler works as expected:
.get("/test", () => 1, { response: { 200: t.Number(), 418: t.Union([t.Literal("foo"), t.Literal("bar")]), }, })
reported on discord
Dependencies
Code
Err
has type{status: unknown, value: unknown}
instead of{status: 418, value: "foo" | "bar"}
Additional Informations
adding type to handler works as expected:
reported on discord