TS linter complains about "body" has implicitly an "any" type for some routes in the same file
nivaldomcj opened this issue · comments
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