elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.59k stars 226 forks source link

Error: ValueClone: Unable to clone value on, when using a t.File in an t.Intersect #824

Open torbjorn-kvist opened 2 months ago

torbjorn-kvist commented 2 months ago

What version of Elysia is running?

1.1.12

What platform is your computer?

Darwin 22.4.0 arm64 arm

What steps can reproduce the bug?

import Elysia, { t } from 'elysia'

export const userSchema = t.Intersect([
  t.Object({ some: t.Optional(t.String()) }),
  t.Object({
    some3: t.Optional(t.String()),
    avatar: t.Optional(t.File()),
  }),
])

const app = new Elysia().post('/test', () => ({}), {
  body: userSchema,
  response: userSchema,
})

const formData = new FormData()
formData.append('some', 'value')
formData.append('some3', 'value')
formData.append('avatar', new File([''], 'avatar.png'))

const response = await app.handle(
  new Request('http://localhost/test', {
    method: 'POST',
    body: formData,
  }),
)

console.log(response, await response.text())

image

What is the expected behavior?

No errors and working similar to when directly creating the t.Object without using t.Intersect

export const userSchema = t.Object({
  some: t.Optional(t.String()),
  some3: t.Optional(t.String()),
  avatar: t.Optional(t.File()),
})

What do you see instead?

Throws {"name":"Error","message":"ValueClone: Unable to clone value"}

Additional information

Probably a similar issue as #796

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

Yes