Skip to content

Defining a Type from TypeBox and preserve tags #850

Answered by sinclairzx81
gonzauy asked this question in Q&A
Discussion options

You must be logged in to vote

@gonzauy Hello!

I don't know of a way to map schema options to JsDoc comments in the type system, but you can apply JsDoc comments manually and have them come through on the static type.

TypeScript Link Here

import { Type, Static } from '@sinclair/typebox'

export const SchemaTest = Type.Object(
  {
    /** 
     * The name of the user
     */
    name: Type.String({ description: 'The name of the user' }),
    /** 
     * The age of the user, must be at least 18 
     * @minimum 18
     * @maximum 100
     */
    age: Type.Number({
      minimum: 18,
      maximum: 100,
      description: 'The age of the user, must be at least 18',
    }),
  },
);

export type MyType = Static<typeof Schem…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gonzauy
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants