Replies: 2 comments
-
|
@ThallesP Hi,
TypeBox can only parse static type information (syntax that would otherwise be erased on compile), but where class definitions fall into the runtime constructs category (i.e. class definitions are runtime JavaScript values). Because This said, TypeBox does let you to describe type level import Type from 'typebox'
// Define Constructor Signature
const CtorDef = Type.Script(`new () => { id: string }`)
console.log(CtorDef)
// Usage
declare const Ctor: Type.Static<typeof CtorDef>
const instance = new Ctor()
const { id } = instance // safeBut these probably shouldn't be used with Elysia / OpenAPI as they are meant specifically for custom IDL modelling (interface definition language) and to express intrinsic TypeScript syntax. Constructor types can't be used for validation. Hope this helps |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the fast answer! After taking a closer look, I may have a workaround. It turns out that the .d.ts generated by instead of: I searched around and found this type helper which simplifies/forces TypeScript to inline the whole class as a simple object: Not at all related to typebox and probably not useful to you, but I just wanted to mark an end to this thread. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I've been trying to use Elysia's openapi type-gen and was wondering why no types for classes were being generated.
After looking into the code, I found that typebox can't generate JSON schemas for classes. Are there any workarounds? I guess it makes sense since classes aren't exactly TypeScript, but I just wanted to confirm.
Beta Was this translation helpful? Give feedback.
All reactions