-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
Broken t.Files()
and issues with t.File()
when not returned alone
#1023
Comments
I think Typescript gives the error correctly. You can't return a file with a JSON. That's why Typescript complain Take this 2 routes for example:
The And the {
"file": {},
"text": "hello"
} Edit: I believe this also answers your other similar issue (#1019) |
Yes I see your point, I also considered that possibility before opening this issue. The official documentation lists my examples as the correct way to do things, it says the response will automatically be https://elysiajs.com/integrations/cheat-sheet#return-a-file By reading the TypeScript errors I'm pretty this is just a type mismatch where the Elysia So I don't think this solves this issue no... please correct me if I'm missing anything. |
Then maybe, this what you intended for: https://elysiajs.com/essential/handler#formdata |
Tried both the original from the cheat sheet docs and the one you just gave me with the // ROUTE 1
.get("/like-cheat-sheet-documentation-but-with-formdata-typebox", () => form({
hello: 'Elysia',
image: file("example.png")
}),
{
response: t.Object({
hello: t.String(),
image: t.File()
})
})
// ROUTE 2
.get("/like-handler-formdata-documentation-but-with-typebox", () => form({
name: 'Tea Party',
images: [file("example.png"), file("example.png")]
}),
{
response: t.Object({
name: t.String(),
images: t.Files(),
})
}) ROUTE 1:
ROUTE 2:
I would like to note that all these things I'm mentioning work by themselves, it's just adding the TypeBox schema that breaks everything, which is unfortunate the TypeBox + Eden combo is one of the main reasons for my usage and migration to Elysia. Anyways, thanks for all your help and suggestions @hisamafahri, hopefully this will get sorted out or we figure out a workaround in the meantime. |
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 some simple GET requests for files, like this:
What is the expected behavior?
No errors and files are successfully returned.
What do you see instead?
Following my reproduction example, here is the TS error output for each route.
ROUTE 3
ROUTE 4
ROUTE 5
Additional information
Hi again, I've been loving the Elysia experience, especially using the Eden connector with my frontend. Everything has been great except lately I have been finding increasingly more issues with the
t.File()
andt.Files()
TypeBox validators.In this case, all the errors above seem to boil down to the
t.File()
implemented by the Elysia accepting onlystring
for thename
property whileBunFile
hasstring | undefined
, so hopefully this is an easy fix for you. I find it weird that fort.File()
errors only show when it is not returned alone, but that is probably something implementation specific that I'm not aware.I also tried using the
file()
wrapper provided by Elysia instead ofBun.file()
as per this documentation here, but this gives yet another different error, for which I have opened #1019 separately as I wasn't sure it was related to this.I'm surprised to see these very common usage problems not having open issues so I'm worried it be just me that's doing something wrong, please let me know if that is the case. I have tried updating both
elysia
and@types/bun
to the latest version and have cleanednode_modules
andbun.lockb
many times with each reinstall.Once again, thank you for all your work on Elysia, I respect the massive undertaking this project is and am really enjoying using it.
I would love to contribute some documentation with more examples for working with files once this is fixed, assuming I'm doing it right! 😁
Have you tried removing the
node_modules
andbun.lockb
and try again yet?👍
The text was updated successfully, but these errors were encountered: