Skip to content

body type is always unknown despite validation #1115

@JohnRoseDev

Description

@JohnRoseDev

What version of Elysia is running?

1.2.25

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

Define a route with a body validation config:

export const app = new Elysia()
  .post('/do_something', async ({ body }) => {

  }, {
    body: t.Object({
      foo: t.Integer(),
      bar: t.Integer(),
    }),
  })

What is the expected behavior?

The body object from the context parameter should be typed as { foo: number, bar: number }.

What do you see instead?

The body object from the context parameter is typed as unknown.

Additional information

This started happening some months ago and I was under the impression that eventually, upgrading Elysia each time there's a new version would fix this but it's still happening. I assume something in my tsconfig might be off but I've been using this same tsconfig since the beginning of my Elysia project and this problem was not there initially.

bun version:
1.2.4

"bun-types": "1.2.4"

tsconfig:

{
  "compilerOptions": {
    "lib": ["ESNext"],
    "module": "esnext",
    "target": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "esModuleInterop": true,
    "downlevelIteration": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "allowJs": true,
    "preserveSymlinks": true,
    "strictNullChecks": true,
    "types": ["bun-types"],
  }
}

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