Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Elysia file() wrapper breaks t.File() schema #1019

Open
dy0gu opened this issue Jan 17, 2025 · 0 comments
Open

Using the Elysia file() wrapper breaks t.File() schema #1019

dy0gu opened this issue Jan 17, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@dy0gu
Copy link

dy0gu commented Jan 17, 2025

What version of Elysia is running?

1.2.10

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Create a simple GET request for a file:

.get("/favicon.ico", () => file("src/assets/images/favicon.ico"), {
  response: t.File({
    description: "Returns a logo for the API to display in browsers.",
  }),
})

What is the expected behavior?

No typescript or runtime errors.

What do you see instead?

Typescript outputs the following error, among others:

...

Type 'ElysiaFile' is not assignable to type 'Response | File | BunFile'.

...

Ignoring the type error and trying to access the route at runtime anyways returns this json:

{
  "type": "validation",
  "on": "response",
  "summary": "Expected kind 'File'",
  "property": "root",
  "message": "Expected kind 'File'",
  "expected": "File",
  "found": {
    "path": "src/assets/images/favicon.ico",
    "value": {}
  },
  "errors": [
    {
      "summary": "Expected kind 'File'",
      "type": 31,
      "schema": {
        "default": "File",
        "description": "Returns a logo for the API to display in browsers.",
        "type": "string",
        "format": "binary",
        "additionalProperties": false
      },
      "path": "",
      "value": {
        "path": "src/assets/images/favicon.ico",
        "value": {}
      },
      "message": "Expected kind 'File'",
      "errors": []
    }
  ]
}

Additional information

I've been enjoying the development experience with Elysia lately, especially with the efforts you've been making to add wrappers around Bun and Node to maintain a runtime independence.

It struck me as odd that there was no open issue for this problem, I tried searching hard for a while before opening this. The official Elysia docs already use the file() wrapper the framework provides so I'm surprised no one has ran into this case yet.

I understand Node support is not a priority, if this qualifies as that, but hopefully the t.File() type can be easily updated to include the wrapper as I personally prefer not relying on runtime syntax as a best practice. Which I try to do whenever possible with a framework that provides as much out of the box as Elysia does.

Have you try removing the node_modules and bun.lockb and try again yet?

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant