elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.27k stars 219 forks source link

Strange "error()" behavior with response schema #710

Closed itsnoctural closed 1 month ago

itsnoctural commented 3 months ago

What version of Elysia.JS is running?

1.0.27

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

import { Elysia, t } from "elysia";

new Elysia()
  .get(
    "/",
    ({ error }) => {
      const hello = false;

      if (!hello) {
        return error(400);
      }

      return { example: "Hello" };
    },
    {
      response: {
        200: t.Object({ example: t.String() }),
      },
    },
  )
  .listen(8080);

What is the expected behavior?

No response

What do you see instead?

Expected 2 arguments, but got 1. ts(2554)
context.d.ts(73, 301): An argument for 'response' was not provided.

Additional information

No response

SaltyAom commented 1 month ago

This is an expected behavior, as 400 response is not defined in response schema, it's not allowed to used unless explicitly defined.