elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Global Schema does not work

Open youcefs21 opened this issue 1 year ago • 3 comments

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

youcefs21 avatar Dec 30 '23 23:12 youcefs21

same here

tjapa avatar Dec 31 '23 01:12 tjapa

also having this issue

erhant avatar Jan 19 '24 21:01 erhant

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.

cybercoder-naj avatar Mar 09 '24 00:03 cybercoder-naj

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.

SaltyAom avatar Aug 30 '24 18:08 SaltyAom