Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS linter complains about "body" has implicitly an "any" type for some routes in the same file #733

Open
nivaldomcj opened this issue Jul 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nivaldomcj
Copy link

nivaldomcj commented Jul 18, 2024

What version of Elysia.JS is running?

1.1.1

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

After update from 1.0.27 to 1.1.1, in my project TSC complains about some route handlers not having a type for body. The strange part is, some routes is ok (even for routes of same file), TSC do not complain and my IDE shows the correct type of it, but others not.

There is an example of code that reproduces the current behavior:

index.ts

const PORT = Bun.env.PORT ?? 3000

const app = new Elysia()
  .use(coreHandlers)
  .listen(PORT)

core.ts

export const coreHandlers = new Elysia()
  .guard({
    beforeHandle: ({ set, headers }) => {
      // this works, `set` and `headers` has the correct types
    },
  })
  .use(eventModel)
  .post(
    "/r",
    async ({ body, headers }) => {
      // these types also works
    },
    {
      body: "input",
      response: "output",
    }
  )
  .post("/i", async ({ body }) => {
    // this does not work, it complains about `body` being any
  }, {
    body: "onlyIds",
    response: t.Any(),
  })

event.ts

const idsModel = t.Object(
  {
    // ...
  },
  { additionalProperties: true }
)

export const eventModel = new Elysia().model({
  onlyIds: t.Object(
    {
      ids: idsModel,
    },
    { additionalProperties: true }
  ),
  input: t.Object(
    {
      // some code goes here...
    },
    { additionalProperties: true }
  ),
  output: t.Object(
    {
      // some code goes here...
    },
    { additionalProperties: true }
  ),
})

What is the expected behavior?

This code should work and compiler should not complain about any issue.

What do you see instead?

❯ bun tsc --noEmit
src/handlers/core.ts:140:14 - error TS7031: Binding element 'body' implicitly has an 'any' type.

140     async ({ body, store }) => {
                 ~~~~

error: "tsc" exited with code 2

Additional information

Bun v1.1.19

@nivaldomcj nivaldomcj added the bug Something isn't working label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant