Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.28.3 #406

Merged
merged 7 commits into from
Apr 21, 2023
Merged

Revision 0.28.3 #406

merged 7 commits into from
Apr 21, 2023

Conversation

sinclairzx81
Copy link
Owner

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())

@sinclairzx81 sinclairzx81 merged commit 749b453 into master Apr 21, 2023
@sinclairzx81 sinclairzx81 deleted the rest branch April 21, 2023 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant