deno.land / x / typebox@0.32.21 / changelog / 0.28.3.md

0.28.3

Overview

Revision 0.28.3 adds a new Rest type to support variadic type composition.

Contents

Variadic Types

Revision 0.28.3 adds a new type named Type.Rest. This type is used to extract a tuple array of type of [...TSchema]. The return value of this type is not strictly JSON Schema, however the tuple array can be used as a parameter to other types that accept tuples as their arguments.

Tuple Concatenation

// TypeScript

type A = [1, 2]

type B = [3, 4]

type C = [...A, ...B]

// TypeBox

const A = Type.Tuple([Type.Literal(1), Type.Literal(2)])

const B = Type.Tuple([Type.Literal(3), Type.Literal(4)])

const C = Type.Tuple([...Type.Rest(A), ...Type.Rest(B)])

Tuple To Parameter

// TypeScript

type P = [number, number]

type F1 = (param: [...P]) => void

type F2 = (param: [...P, number]) => void

// TypeBox

const P = Type.Tuple([Type.Number(), Type.Number()])

const F1 = Type.Function(Type.Rest(P), Type.Void())

const F2 = Type.Function([...Type.Rest(P), Type.Number()], Type.Void())
typebox

Version Info

Tagged at
4 weeks ago