@traversable/schema
    Preparing search index...
    • Converts an arbitrary typebox schema into a string representing its underlying TypeScript type.

      Parameters

      • schematic: TAnySchema
      • Optionaloptions:
            | {
                includeNewtypeDeclaration?: boolean;
                preferInterface: boolean;
                typeName: string;
            }
            | { typeName?: string }
        • {
              includeNewtypeDeclaration?: boolean;
              preferInterface: boolean;
              typeName: string;
          }
          • OptionalincludeNewtypeDeclaration?: boolean
          • preferInterface: boolean

            Use the preferInterface option to tell the compiler that you'd prefer the generated type to be an interface, if possible.

            Note: This option has no effect unless you give you name a type via options.typeName toType.Options.typeName.

            console.log(box.toType(T.Object({ a: T.Number() }), { typeName: 'MyType' }))
            // => type MyType = { a: number }

            console.log(box.toType(T.Object({ a: T.Number() }), { typeName: 'MyType', preferInterface: true }))
            // => interface MyType { a: number }
          • typeName: string
        • { typeName?: string }
          • OptionaltypeName?: string

            Use Options.typeName to give you type a name. If no type name is provided, the returned type will be anonymous.

            console.log(box.toType(T.Number()))                         // => number
            console.log(box.toType(T.Number(), { typeName: 'MyType' })) // => type MyType = number

      Returns string

      import * as vi from 'vitest'
      import * as T from '@sinclair/typebox'
      import { box } from '@traversable/typebox'

      vi.expect(box.toType(
      T.Record(T.Enum({ a: 'A', b: 'B', c: 'C' }), T.Literal(1))
      )).toMatchInlineSnapshot
      (`"{ A: 1, B: 1, C: 1 }"`)

      vi.expect(box.toType(
      T.Intersect([T.Number(), T.Union([T.Literal(1), T.Literal(2), T.Literal(3)])])
      )).toMatchInlineSnapshot
      (`"number & (1 | 2 | 3)"`)

      vi.expect(box.toType(
      T.Object({
      x: T.Optional(T.Array(T.Number())),
      y: T.Optional(T.Array(T.Number())),
      z: T.Optional(T.Array(T.Number())),
      })
      )).toMatchInlineSnapshot
      (`"{ x?: Array<number>, y?: Array<number>, z?: Array<number> }"`)

      // Use the `typeName` option to give you type a name:
      vi.expect(box.toType(
      T.Object({ a: T.Optional(T.Number()) }),
      { typeName: 'MyType' }
      )).toMatchInlineSnapshot
      (`"type MyType = { a?: number }"`)