Skip to content

Using Typescript types/interfaces as input for Typebox Types #317

Answered by sinclairzx81
sherzod-sync asked this question in Q&A
Discussion options

You must be logged in to vote

@sherzod-sync Hi,

Unfortunately this isn't possible in TypeScript as all type information is erased on compilation. Because type information is erased, there is nothing available to compute the Type.Array(Type.Number()) at runtime.

However, there are alternative solutions to this, but each requires custom compiler transformations / plugins. These kinds of solutions usually take the TypeScript Compiler API as a dependency and use it to intercept the compilation to read type information available gathered during a compilation pass. This type information can then be emitted to JavaScript (to be available at runtime) or used to build reflection lookups (which can also be used at runtime)

Type…

Replies: 4 comments 20 replies

Comment options

You must be logged in to vote
2 replies
@sherzod-sync
Comment options

@xddq
Comment options

Answer selected by sherzod-sync
Comment options

You must be logged in to vote
9 replies
@xddq
Comment options

@sinclairzx81
Comment options

@xddq
Comment options

@sinclairzx81
Comment options

@xddq
Comment options

Comment options

You must be logged in to vote
4 replies
@xddq
Comment options

@xddq
Comment options

@sinclairzx81
Comment options

@burakakca
Comment options

Comment options

You must be logged in to vote
5 replies
@xddq
Comment options

@gorbak25
Comment options

@xddq
Comment options

@gorbak25
Comment options

@xddq
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants