Skip to content

Treaty losing type when using Elysia.t for array of literals #252

@brianjor

Description

@brianjor

What version of Elysia is running?

"@elysiajs/eden": "1.4.8",
"elysia": "1.4.26",
"zod": "4.3.6"

What platform is your computer?

Windows 10 WSL2 Ubuntu

What steps can reproduce the bug?

import { Elysia, t } from "elysia";
import { z } from "zod";
import { treaty } from "@elysiajs/eden/treaty2";

const topics = ["topic1", "topic2"] as const;
const TTopicsSchema = t.Array(t.Union(topics.map((topic) => t.Literal(topic))));
const ZTopicsSchema = z.array(z.union(topics.map((topic) => z.literal(topic))));

// Using Elysia.t
const tapp = new Elysia().ws("/ws", {
  query: t.Object({
    topics: TTopicsSchema,
  }),
});

const tapi = treaty<typeof tapp>("localhost");

tapi.ws.subscribe({
  query: {
    topics: ["topic1"], // <-- Type 'string' is not assignable to type 'never'.
  },
});

// Using zod
const zapp = new Elysia().ws("/ws", {
  query: z.object({
    topics: ZTopicsSchema,
  }),
});

const zapi = treaty<typeof zapp>("localhost");

zapi.ws.subscribe({
  query: {
    topics: ["topic1"],
  },
});

What is the expected behavior?

In tapi.ws.subscribe query.topics should have the type: ("topic1" | "topic2")[]. The zod example shows it correctly.

What do you see instead?

It has the type never[]

Additional information

No response

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

No response

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