Closed
Description
What version of Elysia is running?
1.3.0
What platform is your computer?
Darwin 24.4.0 arm64 arm
What steps can reproduce the bug?
After upgrading to 1.3.0, Elysia no longer seems to properly validate the schema with t.Optional(t.Nullable())
. Here's a very simple repro:
import { treaty } from '@elysiajs/eden';
import { Elysia, t } from 'elysia';
const app = new Elysia().post(
'/test',
({ body }) => {
console.log({ body });
return 'Hello Elysia';
},
{
body: t.Object({
foo: t.Optional(
t.Nullable(
t.Number({
// 'foo' but be either number, optional or nullable
error: 'Must be a number',
}),
),
),
}),
},
);
const api = treaty(app);
const { data, error } = await api.test.post({
// I'm passing in a string for `foo` here. This should fail validation.
// TypeScript correctly throws an error here.
foo: 'asd',
});
// I expect `error` to be defined here, but Elysia 1.3.0 returns `error: null` here. Elysia 1.2.x would return an error.
console.log({ data, error });
This problem also happens if using Type.Partial()
instead of Type.Optional()
FWIW: Using t.MaybeEmpty()
instead of t.Optional(t.Nullable())
throws the error, but doesn't account for optional keys.
What is the expected behavior?
I expect Elysia 1.2 and 1.3 behaviour to match and return errors if a non-matching value is passed into t.Optional(t.Nullable())
What do you see instead?
Elysia 1.3 bypasses schema validation
Additional information
No response
Have you try removing the node_modules
and bun.lockb
and try again yet?
Yes