elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Cannot use Plain Typebox Types for Schema

Open sv2dev opened this issue 1 year ago • 8 comments
trafficstars

What version of Elysia.JS is running?

1.0.25

What platform is your computer?

No response

What steps can reproduce the bug?

Try to use a schema, created with TypeBox for an HTTP endpoint.

What is the expected behavior?

No type errors

What do you see instead?

Type error: schema.d.mts(21, 5): '[Kind]' is declared here.

Additional information

Until recently, this worked for me. I double-checked and this issue did not occur in 1.0.24. From my point of view, it makes sense to define types in typebox outside of elysia. This way I can reuse my schema in other places without having elysia as a shared dependency.

sv2dev avatar Jun 23 '24 15:06 sv2dev

I've been facing the same issue.

Even when using "drizzle-typebox" with PostgreSQL as shown here https://elysiajs.com/integrations/drizzle.html.

CGuiho avatar Jul 20 '24 14:07 CGuiho

svi3c have you found a workaround?

CGuiho avatar Jul 20 '24 14:07 CGuiho

svi3c have you found a workaround?

Just override typebox version in package.json

"overrides": {
        "@sinclair/typebox": "^0.32.15"
    },

kravetsone avatar Jul 20 '24 16:07 kravetsone

I was coming to report the same issue, but this issue showed up only in the new version v1.1

omarkhatibco avatar Jul 20 '24 18:07 omarkhatibco

same here the solution from kravetsone worked thanks

cannap avatar Jul 21 '24 12:07 cannap

svi3c have you found a workaround?

Just override typebox version in package.json

"overrides": {
        "@sinclair/typebox": "^0.32.15"
    },

This worked for me, thanks!

sbastidasr avatar Sep 09 '24 20:09 sbastidasr

This does not work in a monorepo setup.

masterT avatar Sep 19 '24 08:09 masterT

This does not work in a monorepo setup.

override tip works

kravetsone avatar Sep 19 '24 10:09 kravetsone

"overrides": {
    "@sinclair/typebox": "0.33.17"
  },

This doesn't seem to be working. I have both my packages set at the same typebox version. Have deleted node modules, restarted typescript & editor. This is migrating from a fastify project using 0.33.17.

server.post('/test', async ({ body }) => {
  console.log({body})
  return body.name; // 'body' is of type 'unknown'.
}, {
  body: t.Object({ // Property '[Kind]' is missing in type 'TObject<{ name: TString; }>' but required in type 'TSchema'
    name: t.String(),
  })
});

Any suggestions? I'll try downgrade to "0.32.34" and report back

Edit: Downgrading works fine.

joshmeads avatar Oct 21 '24 20:10 joshmeads

This issue seems to be solved. I can't reproduce it with

[email protected]
@sinclair/[email protected]

sv2dev avatar Feb 01 '25 11:02 sv2dev

I had installed @sinclair/typebox separately (even though the same version as elysia), which was causing the issue. Removed it and I don't see this error anymore. Now I'm using import { t } from 'elysia' everywhere.

harshjv avatar Jun 29 '25 06:06 harshjv