elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Optional params not work

Open Farnsi opened this issue 1 year ago • 3 comments

View closed https://github.com/elysiajs/elysia/issues/68 exactly the same problem

elysia: 0.8.9 @elysiajs/eden: 0.8.1

Farnsi avatar Jan 22 '24 16:01 Farnsi

Probably caused this to regress too? https://github.com/elysiajs/elysia/issues/436

floydjones1 avatar Jan 22 '24 16:01 floydjones1

fr.

SupertigerDev avatar Apr 28 '24 19:04 SupertigerDev

Same problem here, t.Optional() and I'm getting a validation error.

JustMrMendez avatar Jul 09 '24 18:07 JustMrMendez

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.

SaltyAom avatar Aug 30 '24 18:08 SaltyAom

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.

SupertigerDev avatar Aug 30 '24 19:08 SupertigerDev

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

SaltyAom avatar Sep 04 '24 05:09 SaltyAom

Screenshot 2024-09-06 at 1 34 56 PM

elysia: 1.1.12 This is happening to me too, I'm expecting query to be of type:

{
  pageNum: number;
  pageSize: number;
}

jasperdunn avatar Sep 06 '24 03:09 jasperdunn

Screenshot 2024-09-06 at 1 34 56 PM

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?

kravetsone avatar Sep 06 '24 05:09 kravetsone

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

jasperdunn avatar Sep 06 '24 06:09 jasperdunn

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

Ahh sorry i misunderstood

Can you check it with plain typebox? With Static

kravetsone avatar Sep 06 '24 08:09 kravetsone

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

jasperdunn avatar Sep 08 '24 01:09 jasperdunn