Skip to content

t.Files validator breaks for response schema #1239

Closed
@dy0gu

Description

@dy0gu

What version of Elysia is running?

1.3.4 (but this is an old bug, see #1023)

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

Try any of these minimal instances:

1

/* 
Type 'BunFile[]' is not assignable to type 'File[]'.
Type 'BunFile' is not assignable to type 'File'.
Types of property 'name' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
*/
new Elysia().get("/test", () => {
	return {
		files: [Bun.file("test.png"), Bun.file("test.png")],
		text: "hello",
	};
}, {
	response: t.Object({
		files: t.Files(),
		text: t.String(),
	}),
})

2

/* 
Type 'ElysiaFile[]' is not assignable to type 'File[]'.
Type 'ElysiaFile' is missing the following properties from type 'File': lastModified, name, size, json, and 5 more.
*/
new Elysia().get("/test", () => {
		return {
			files: [file("test.png"), file("test.png")],
			text: "hello",
		};
	}, {
		response: t.Object({
			files: t.Files(),
			text: t.String(),
		}),
	})

3

/* 
The types of '[ELYSIA_FORM_DATA].files' are incompatible between these types.
The type 'readonly [ElysiaFile, ElysiaFile]' is 'readonly' and cannot be assigned to the mutable type 'File[]'.
*/
new Elysia().get("/test", () => {
		return form({
                        // Same "is 'readonly' ..." error if using Bun.File here
			files: [file("test.png"), file("test.png")],
			text: "hello",
		});
	}, {
		response: t.Form({
			files: t.Files(),
			text: t.String(),
		}),
	})

What is the expected behavior?

No type errors and no runtime throw.

What do you see instead?

I get type errors and the route throws if I call it.

Additional information

No response

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

Yes

Metadata

Metadata

Assignees

No one assigned

    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