tuple-ts 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,9 +78,9 @@ Type-narrowed tuple factories are also supported:
78
78
 
79
79
  ```ts
80
80
  type Point = [number, number];
81
- const Point = tuple.narrow<Point>();
81
+ const Point = tuple.typed<Point>();
82
82
  // Or equivalently, using an exemplar:
83
- // const Point = tuple.narrow(0, 0);
83
+ // const Point = tuple.typed(0, 0);
84
84
 
85
85
  type P = Parameters<typeof Point>; // [number, number];
86
86
  ```
@@ -102,14 +102,14 @@ tuple(10, 20) === tuple(10, 21); // false!
102
102
  tuple(10, 20) === tuple(20, 10); // false!
103
103
  ```
104
104
 
105
- ### Constraining a tuple factory with `.narrow()`
105
+ ### Constraining a tuple factory with `.typed()`
106
106
 
107
- Use `.narrow()` to make a reusable tuple factory whose arguments must satisfy a nominated tuple type.
107
+ Use `.typed()` to make a reusable tuple factory whose arguments must satisfy a nominated tuple type.
108
108
 
109
109
  Specify the type explicitly:
110
110
 
111
111
  ```ts
112
- const Point = tuple.narrow<[number, number]>();
112
+ const Point = tuple.typed<[number, number]>();
113
113
 
114
114
  Point(10, 20); // OK
115
115
  Point(10, "20"); // TypeScript error
@@ -118,7 +118,7 @@ Point(10, "20"); // TypeScript error
118
118
  You can alternatively provide an exemplar from which the type constraint will be inferred:
119
119
 
120
120
  ```ts
121
- const NumberPair = tuple.narrow(0, 0);
121
+ const NumberPair = tuple.typed(0, 0);
122
122
 
123
123
  NumberPair(10, 20); // OK
124
124
  NumberPair(10, "20"); // TypeScript error
@@ -193,40 +193,40 @@ The returned value contains the tuple slots and the schema's named properties, n
193
193
 
194
194
  ### Constraining a struct factory
195
195
 
196
- Just like `tuple`, structs support `.narrow()` to specify the struct's value types positionally:
196
+ Just like `tuple`, structs support `.typed()` to specify the struct's value types positionally:
197
197
 
198
198
  ```ts
199
- const Point = struct(["x", "y"]).narrow<[number, number]>();
199
+ const Point = struct(["x", "y"]).typed<[number, number]>();
200
200
 
201
201
  Point(10, 20); // OK
202
202
  Point(10, "20"); // TypeScript error
203
203
  ```
204
204
 
205
- Use `.narrowFrom()` when you want to express the value types by label instead:
205
+ Use `.typedFrom()` when you want to express the value types by label instead:
206
206
 
207
207
  ```ts
208
208
  type Coordinates = { x: number; y: number };
209
209
 
210
- const Point = struct(["x", "y"]).narrowFrom<Coordinates>();
210
+ const Point = struct(["x", "y"]).typedFrom<Coordinates>();
211
211
 
212
212
  Point(10, 20); // OK
213
213
  Point(10, "20"); // TypeScript error
214
214
  Point.from({ x: 10, y: 20 }); // OK
215
215
  ```
216
216
 
217
- You can also provide a typed exemplar to `.narrowFrom()`:
217
+ You can also provide a typed exemplar to `.typedFrom()`:
218
218
 
219
219
  ```ts
220
- const Point = struct(["x", "y"]).narrowFrom({ x: 0, y: 0 });
220
+ const Point = struct(["x", "y"]).typedFrom({ x: 0, y: 0 });
221
221
  ```
222
222
 
223
223
  ### Struct schemas and identity
224
224
 
225
- Each call to `struct(labels)` creates its own cache. Factories narrowed from that schema share the cache, but separate calls to `struct()` create separate caches, even when given identical labels:
225
+ Each call to `struct(labels)` creates its own cache. Factories narrowed from that schema with `.typed()` share the cache, but separate calls to `struct()` create separate caches, even when given identical labels:
226
226
 
227
227
  ```ts
228
- const PointA = struct(["x", "y"]).narrow<[number, number]>();
229
- const PointB = struct(["x", "y"]).narrow<[number, number]>();
228
+ const PointA = struct(["x", "y"]).typed<[number, number]>();
229
+ const PointB = struct(["x", "y"]).typed<[number, number]>();
230
230
 
231
231
  PointA(1, 2) === PointA(1, 2); // true
232
232
  PointA(1, 2) === PointB(1, 2); // false