Skip to content

Standard Validatior: Types not working on Cookies & Query #1401

@touhidurrr

Description

@touhidurrr

What version of Elysia is running?

1.4.4

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What environment are you using

1.2.21

Are you using dynamic mode?

no

What steps can reproduce the bug?

Types not working on Cookies

import { Elysia } from 'elysia';
import { z } from 'zod';

new Elysia()
  .get('test', ({ cookie: { test } }) => test, {
    cookie: z.object({ test: z.string() }),
  })

Types not working on Query

import { Elysia } from 'elysia';
import { z } from 'zod';

new Elysia()
  .get('test', ({ cookie: { test } }) => test, {
    cookie: z.object({ test: z.string() }),
  })

What is the expected behavior?

Cookie

Equivalent TypeBox Code:

import { Elysia, t } from 'elysia';

new Elysia()
  .get('test', ({ cookie: { test } }) => test, {
    cookie: t.Object({ test: t.String() }),
  })

Result:
Image

Query

Equivalent TypeBox Code:

import { Elysia, t } from 'elysia';

new Elysia()
  .get('test', ({ query }) => ({ query }), {
    query: t.Object({ num: t.Numeric() }),
  });

Result:
Image

What do you see instead?

Cookie

Image

Query

Cannot reproduce, but it does not work on one of my nested routes. I do not actually get any error, but instead all validation and coercing in query simply does not work. It just gives you plain string or undefined. Like the following:

{
  "a": "1234", // yes, even after `z.coerce.number()`.
  "b": "true", // yes, i did `z.stringbool()` here.
}

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions