elysia
elysia copied to clipboard
Global Schema does not work
The code example as given in the docs does not work
import { Elysia, t} from 'elysia'
new Elysia()
.get('/none', () => 'hi')
.schema({
query: t.Object({
name: t.String()
})
})
.get('/query', ({ query: { name } }) => name)
.listen(3000)
I'm getting a "This expression is not callable." error on schema. Looking at the types, schema is of type Routes for some reason, which doesn't sound right.
This is not just incorrect typing, putting the code in a js file and trying to run it anyway gives a "schema is not a function." error message
same here
also having this issue
I am having the same issue. Is this being looked at?
Edit
If you have a look at scoped guards, this is the closest that we can achieve for this.
Should have been fixed in the previous subsequent versions of Elysia as unable to reproduce in the latest version (1.1.9) with the following code:
import { Elysia, t } from '../src'
const app = new Elysia()
.get('/none', () => 'hi')
.guard({
query: t.Object({
name: t.String()
})
})
.get('/query', ({ query: { name } }) => name)
.get('/any', ({ query }) => query)
app.handle(new Request('http://localhost:3000/query'))
.then((x) => x.text())
.then(console.log)
app.handle(new Request('http://localhost:3000/query?name=hi'))
.then((x) => x.text())
.then(console.log)
If this doesn't fix your problem, feel free to reopen the issue.