This commit is contained in:
sinclair
2025-12-24 15:44:34 +09:00
commit 13d553220c
1047 changed files with 80931 additions and 0 deletions

57
changelog/0.28.3.md Normal file
View File

@@ -0,0 +1,57 @@
## [0.28.3](https://www.npmjs.com/package/@sinclair/typebox/v/0.28.3)
## Overview
Revision 0.28.3 adds a new Rest type to support variadic type composition.
## Contents
- Enhancements
- [Variadic Types](#Variadic-Types)
<a href="Variadic-Types"></a>
## 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
// 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
// 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())
```