Skip to content

TypeBox Union Type Recognition Regression in Elysia 1.3.8 (t.Union) #1318

@FahimMontasir

Description

@FahimMontasir

What version of Elysia is running?

1.3.8

What platform is your computer?

Darwin 24.5.0 arm64 arm

What steps can reproduce the bug?

  1. Create a simple Drizzle table schema
  2. Generate TypeBox schemas using drizzle-typebox
  3. Create a union schema with composite types using the generated schemas
  4. Set up an Elysia route with this validation
  5. Send valid data that matches the schema structure

Code snippet to reproduce:

import { Elysia, t } from "elysia";
import { createInsertSchema, createSelectSchema } from "drizzle-typebox";
import { pgTable, varchar, text, integer, boolean } from "drizzle-orm/pg-core";

// Simple Drizzle table
const usersTable = pgTable("users", {
  id: integer("id").primaryKey(),
  uid: varchar("uid", { length: 25 }).notNull(),
  username: varchar("username", { length: 50 }).notNull(),
  firstName: varchar("first_name", { length: 100 }),
  bio: text("bio"),
  isOnboarded: boolean("is_onboarded").default(false),
});

const userLanguagesTable = pgTable("user_languages", {
  id: integer("id").primaryKey(),
  userId: integer("user_id").notNull(),
  languageCode: varchar("language_code", { length: 10 }).notNull(),
  level: varchar("level", { length: 20 }),
});

// Generate TypeBox schemas
const UserSelectSchema = createSelectSchema(usersTable);
const UserLanguageSelectSchema = createSelectSchema(userLanguagesTable);

// Problematic union schema with composite + drizzle schemas
const UserProfileSchema = t.Union([
  t.Composite([
    t.Omit(UserSelectSchema, ["id"]),
    t.Object({
      languages: t.Union([
        t.Array(t.Omit(UserLanguageSelectSchema, ["id", "userId"])),
        t.Null(),
      ]),
    }),
  ]),
  t.Null(),
]);

What is the expected behavior?

The validation should pass and return:

{
  "success": true,
  "data": {
    "uid": "user_123",
    "username": "testuser",
    "firstName": "John",
    "bio": "Hello world",
    "isOnboarded": true,
    "languages": [
      { "languageCode": "en", "level": "advanced" }
    ]
  }
}

What do you see instead?

Validation fails with a error:

{
 type: 62,
schema: {
     [Symbol(TypeBox.Kind)]: "Union",
     anyOf: [ ....
message: "Expected union value",
  errors: [
  ValueErrorIterator {
  iterator: {},
    [Symbol(Symbol.iterator)]: [Function],
       First: [Function: First],
     }, ValueErrorIterator {
       iterator: {},
       [Symbol(Symbol.iterator)]: [Function],
       First: [Function: First],
    }, ValueErrorIterator {
      iterator: {},
       [Symbol(Symbol.iterator)]: [Function],
       First: [Function: First],
     }
   ],
:summary: "Value should be one of 'object', 'undefined', 'null'",
}

Additional information

Version Details:

  • Broken: Elysia 1.3.8
  • Working: Elysia 1.3.1
  • drizzle-typebox: 0.3.3

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