-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Typebox Boolean regression in 1.1.17 #872
Comments
Same issue here, was running 1.1.16 so the issue was likely introduced in an earlier version. Tried upgrading but it's still there, defining an optional boolean in a query is always being treated as required |
Can you provide a minimal example to reproduce the issue? Optional boolean query parameters seem to work in Elysia 1.1.23: import Elysia, {t} from 'elysia'
const app = new Elysia()
.get('/test', ({query: {registered}}) => {
return `Registered: ${registered}`
}, {
query: t.Object({registered: t.Optional(t.Boolean())}),
})
const urls = [
'https://example.com/test?registered=true',
'https://example.com/test?registered=false',
'https://example.com/test'
]
for (const url of urls) {
const res = await app.handle(new Request(url))
console.log(url, '→', await res.text())
} Output:
|
@crishoj I almost gave up trying to reproduce it as your snippet seems to work well, but if you add another required property to the |
@ilijapuaca Bingo — reproducible when second query param is added to the schema: import Elysia, {t} from 'elysia'
const app = new Elysia()
.get('/test', ({query: {registered}}) => {
return `Registered: ${registered}`
}, {
query: t.Object({
registered: t.Optional(t.Boolean()),
other: t.String(),
}),
})
const urls = [
'https://example.com/test?other=foo®istered=true',
'https://example.com/test?other=foo®istered=false',
'https://example.com/test?other=foo'
]
for (const url of urls) {
const res = await app.handle(new Request(url))
console.log(url, '→', res.status, await res.text())
} Output |
The issue appears to only affect ahead-of-time optimized handlers, which is Elysia's default: |
Possible fix for the issue: #907 I am not sure I understand the intended behavior of |
What version of Elysia is running?
1.1.17
What platform is your computer?
Linux 6.6.52-1-MANJARO x86_64 unknown
What steps can reproduce the bug?
Create api route where query parameter has a boolean
for example
Submit request and do not include the boolean value, in this case omit
registered
What is the expected behavior?
it works
What do you see instead?
Tybebox Error
Additional information
No response
Have you try removing the
node_modules
andbun.lockb
and try again yet?No response
The text was updated successfully, but these errors were encountered: