Skip to content

MaybeEmpty causes type to be inferred as unknown #1395

@KurtGokhan

Description

@KurtGokhan

What version of Elysia is running?

1.3.21

What platform is your computer?

Darwin 24.6.0 arm64 arm

What environment are you using

Bun v1.2.21

Are you using dynamic mode?

No

What steps can reproduce the bug?

When using t.MaybeEmpty, the top-level type is inferred as unknown. The issue doesn't seem to happen with t.Nullable etc. But it's also reproducible when doing an union with undefined or void, e.g. t.Union([t.Undefined(), ...])

Image

What is the expected behavior?

Expected type of query to be { name: string } | undefined

What do you see instead?

Type of query is unknown

Additional information

This code can reproduce the issue

import { expectTypeOf } from "bun:test";
import { Elysia, t } from "elysia";

const app = new Elysia().get("/", () => "Hello Elysia", {
  query: t.MaybeEmpty(t.Object({ name: t.String() }))
});

expectTypeOf(app["~Routes"].get.query).not.toEqualTypeOf<unknown>();

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