Skip to content

Commit 376e482

Browse files
committedApr 22, 2023
Revision 0.28.4
1 parent 11b09a1 commit 376e482

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed
 

‎readme.md

+27-14
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ License MIT
8383
- [Conditional](#types-conditional)
8484
- [Template](#types-template-literal)
8585
- [Indexed](#types-indexed)
86-
- [Variadic](#types-variadic)
86+
- [Rest](#types-rest)
8787
- [Guards](#types-guards)
8888
- [Unsafe](#types-unsafe)
8989
- [Strict](#types-strict)
@@ -872,30 +872,43 @@ const A = Type.Index(T, ['x']) // type A = T['x']
872872

873873
const B = Type.Index(T, Type.KeyOf(T)) // type B = T[keyof T]
874874
```
875-
<a name='types-variadic'></a>
875+
<a name='types-rest'></a>
876876
877-
### Variadic Types
877+
### Rest Types
878878
879-
Variadic types are supported with `Type.Rest`. This type will extract interior types from a tuple and return them as a flat array. This array can then be passed to other types that accept arrays as arguments.
880-
881-
The following creates variadic functions using the Rest type.
879+
Rest parameters are supported with `Type.Rest`. This function is used to extract interior arrays from tuples to allow them to compose with the JavaScript spread operator `...`. This type can be used for tuple concatination and variadic function composition.
882880
883881
```typescript
884882
// TypeScript
885883

886-
type P = [number, number]
884+
type T = [number, number] // type T = [number, number]
887885

888-
type F1 = (param: [...P]) => void
886+
type C = [...T, number] // type C = [number, number, number]
889887

890-
type F2 = (param: [...P, number]) => void
888+
type F = (...param: C) => void // type F = (
889+
// param0: number,
890+
// param1: number,
891+
// param2: number,
892+
// ) => void
891893

892894
// TypeBox
893895

894-
const P = Type.Tuple([Type.Number(), Type.Number()])
895-
896-
const F1 = Type.Function(Type.Rest(P), Type.Void())
897-
898-
const F2 = Type.Function([...Type.Rest(P), Type.Number()], Type.Void())
896+
const T = Type.Tuple([ // const T: TTuple<[
897+
Type.Number(), // TNumber,
898+
Type.Number() // TNumber,
899+
]) // ]>
900+
901+
const C = Type.Tuple([ // const C: TTuple<[
902+
...Type.Rest(T), // TNumber,
903+
Type.Number() // TNumber,
904+
]) // TNumber
905+
// ]>
906+
907+
const F = Type.Function(Type.Rest(C), Type.Void()) // const F: TFunction<[
908+
// TNumber,
909+
// TNumber,
910+
// TNumber
911+
// ], TVoid>
899912
```
900913
<a name='types-unsafe'></a>
901914

0 commit comments

Comments
 (0)