Skip to content

TypeScript type inference for derived properties fails in beforeHandle for .delete() method #1425

@bbar

Description

@bbar

What version of Elysia is running?

[email protected]

What platform is your computer?

MacOS Sequoia 15.6.1

What environment are you using

1.2.22

Are you using dynamic mode?

No

What steps can reproduce the bug?

import { Elysia } from "elysia";

export const myPlugin = new Elysia({ name: "myPlugin" }).derive(
  { as: "scoped" },
  async ({ set, status }) => {
    return {
      name: "Brent",
    };
  }
);

const app = new Elysia()
  .use(myPlugin)
  .get("/", ({ name }) => "Hello Elysia", {
    // ✅ Works: derived context is available
    beforeHandle: ({ name }) => {
      console.log(name);
    },
  })
  .post("/", ({ name }) => "Hello Elysia", {
    // ✅ Works: derived context is available
    beforeHandle: ({ name }) => {
      console.log(name);
    },
  })
  .delete("/", ({ name }) => "Hello Elysia", {
    // ❌ Fails: derived context is NOT available
    beforeHandle: ({ name }) => {
      console.log(name); // TypeScript error here
    },
  })
  .listen(3000);

What is the expected behavior?

The name property should be available and properly typed in beforeHandle for all HTTP methods, including .delete().

What do you see instead?

TypeScript error on the .delete() route's beforeHandle: Property 'name' does not exist on type '{ body: unknown; query: Record<string, string>; params: {}; headers: Record<string, string | undefined>; cookie: Record<string, Cookie>; server: Server | null; ... }'

Additional information

  • The issue is specific to the .delete() method - other HTTP verbs work correctly
  • The main route handler ({ name }) => "Hello Elysia" works fine for all methods
  • Only the beforeHandle context typing is affected for .delete()
  • This appears to be a TypeScript definition issue rather than a runtime problem

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