elysia
elysia copied to clipboard
Optional params not work
View closed https://github.com/elysiajs/elysia/issues/68 exactly the same problem
elysia: 0.8.9 @elysiajs/eden: 0.8.1
Probably caused this to regress too? https://github.com/elysiajs/elysia/issues/436
fr.
Same problem here, t.Optional()
and I'm getting a validation error.
Unable to reproduce in the latest version (1.1.9) with the following code:
const app = new Elysia().get('/qtest', ({ query }) => query, {
query: t.Object({
pageNum: t.Optional(t.Numeric({ default: 1 })),
pageSize: t.Optional(t.Numeric({ default: 10 }))
})
})
app.handle(new Request('http://localhost/qtest'))
.then((x) => x.json())
.then(console.log)
Probably have been fixed by 1.0 and 1.1, if the problem still persists feel free to reopen the issue.
Unable to reproduce in the latest version (1.1.9) with the following code:
const app = new Elysia().get('/qtest', ({ query }) => query, { query: t.Object({ pageNum: t.Optional(t.Numeric({ default: 1 })), pageSize: t.Optional(t.Numeric({ default: 10 })) }) }) app.handle(new Request('http://localhost/qtest')) .then((x) => x.json()) .then(console.log)
Probably have been fixed by 1.0 and 1.1, if the problem still persists feel free to reopen the issue.
Those are not params... Those are query. We've already discussed this in discord before but you ignored me :pensive:
Edit: seems like its working anyway.
From SupertigerDev, the linked issue is query params, not path params.
Closed as complete, as mentioned by other SupertigerDev comment.
ohh my bad, seems like its working now. sorry, thanks!
https://github.com/elysiajs/elysia/issues/805#issuecomment-2327150666
elysia: 1.1.12
This is happening to me too, I'm expecting query to be of type:
{
pageNum: number;
pageSize: number;
}
elysia: 1.1.12
This is happening to me too, I'm expecting query to be of type:{ pageNum: number; pageSize: number; }
Wtf You mark it as optional and expect it to be required?
Wtf You mark it as optional and expect it to be required?
Sorry if I haven't explained it clearly. This is what I want:
It's optional, if I don't provide a value then it should use the default value. If this is not at all what default
is for, then please help me understand.
The client query
object should have number | undefined
properties sure, but the server itself should know that the values exist at the beforeHandle
shouldn't it? Or does the default get applied after validation? 🤔
Thanks
Wtf You mark it as optional and expect it to be required?
Sorry if I haven't explained it clearly. This is what I want:
It's optional, if I don't provide a value then it should use the default value. If this is not at all what
default
is for, then please help me understand.The client
query
object should havenumber | undefined
properties sure, but the server itself should know that the values exist at thebeforeHandle
shouldn't it? Or does the default get applied after validation? 🤔Thanks
Ahh sorry i misunderstood
Can you check it with plain typebox?
With Static
Can you check it with plain typebox? With
Static
Reading through again I think my issue is different to the original, I'll write up a separate issue. I'll try and explain it better there, thanks.
Here: https://github.com/elysiajs/elysia/issues/817