ts-data-forge 5.1.1 → 6.1.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.
Files changed (53) hide show
  1. package/dist/array/impl/array-utils-reducing-value.d.mts +28 -0
  2. package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
  3. package/dist/array/impl/array-utils-reducing-value.mjs +4 -1
  4. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  5. package/dist/array/impl/index.mjs +1 -1
  6. package/dist/collections/imap.d.mts +1 -1
  7. package/dist/collections/iset-mapped.d.mts +1 -1
  8. package/dist/collections/iset.d.mts +1 -1
  9. package/dist/guard/is-record.d.mts.map +1 -1
  10. package/dist/guard/is-record.mjs +1 -1
  11. package/dist/guard/is-record.mjs.map +1 -1
  12. package/package.json +52 -48
  13. package/src/array/impl/array-utils-overload-type-error.test.mts +4 -2
  14. package/src/array/impl/array-utils-reducing-value.mts +48 -0
  15. package/src/collections/imap.mts +1 -1
  16. package/src/collections/iset-mapped.mts +1 -1
  17. package/src/collections/iset.mts +1 -1
  18. package/src/functional/optional.test.mts +7 -5
  19. package/src/functional/result.test.mts +10 -8
  20. package/src/functional/ternary-result.test.mts +4 -4
  21. package/src/guard/has-key.test.mts +89 -186
  22. package/src/guard/is-record.mts +1 -2
  23. package/src/guard/is-record.test.mts +57 -67
  24. package/src/json/json.test.mts +5 -5
  25. package/src/number/branded-types/finite-number.test.mts +15 -11
  26. package/src/number/branded-types/int.test.mts +13 -13
  27. package/src/number/branded-types/int16.test.mts +15 -15
  28. package/src/number/branded-types/int32.test.mts +15 -15
  29. package/src/number/branded-types/non-negative-finite-number.test.mts +19 -15
  30. package/src/number/branded-types/non-negative-int16.test.mts +15 -15
  31. package/src/number/branded-types/non-negative-int32.test.mts +15 -15
  32. package/src/number/branded-types/non-zero-finite-number.test.mts +18 -18
  33. package/src/number/branded-types/non-zero-int.test.mts +18 -14
  34. package/src/number/branded-types/non-zero-int16.test.mts +19 -15
  35. package/src/number/branded-types/non-zero-int32.test.mts +19 -15
  36. package/src/number/branded-types/non-zero-safe-int.test.mts +22 -18
  37. package/src/number/branded-types/non-zero-uint16.test.mts +15 -15
  38. package/src/number/branded-types/non-zero-uint32.test.mts +15 -15
  39. package/src/number/branded-types/positive-finite-number.test.mts +18 -18
  40. package/src/number/branded-types/positive-int.test.mts +22 -16
  41. package/src/number/branded-types/positive-int16.test.mts +14 -14
  42. package/src/number/branded-types/positive-int32.test.mts +14 -14
  43. package/src/number/branded-types/positive-safe-int.test.mts +20 -18
  44. package/src/number/branded-types/positive-uint16.test.mts +15 -15
  45. package/src/number/branded-types/positive-uint32.test.mts +15 -15
  46. package/src/number/branded-types/safe-int.test.mts +21 -17
  47. package/src/number/branded-types/safe-uint.test.mts +22 -16
  48. package/src/number/branded-types/uint.test.mts +14 -14
  49. package/src/number/branded-types/uint16.test.mts +14 -14
  50. package/src/number/branded-types/uint32.test.mts +14 -14
  51. package/src/number/enum/int8.test.mts +1 -1
  52. package/src/number/enum/uint8.test.mts +1 -1
  53. package/src/others/memoize-function.test.mts +1 -0
@@ -1,223 +1,126 @@
1
1
  import { expectType } from '../expect-type.mjs';
2
2
  import { hasKey, type HasKeyReturnType } from './has-key.mjs';
3
3
 
4
- {
5
- expectType<
6
- HasKeyReturnType<Readonly<{ a: 0 }> | Readonly<{ b: 1 }>, 'a'>,
7
- Readonly<{ a: 0 }>
8
- >('=');
9
-
10
- expectType<
11
- HasKeyReturnType<Readonly<{ a: 0 }> | Readonly<{ b: 1 }>, 'b'>,
12
- Readonly<{ b: 1 }>
13
- >('=');
14
-
15
- expectType<
16
- HasKeyReturnType<Readonly<{ a: 0 }> | Readonly<{ b: 1 }>, 'd'>,
17
- never
18
- >('=');
19
-
20
- expectType<
21
- HasKeyReturnType<
22
- | Readonly<{ a: 0 }>
23
- | Readonly<{ a: 1; b: 1 }>
24
- | Readonly<{ b: 2 }>
25
- | Readonly<{ c: 3 }>,
26
- 'a'
27
- >,
28
- Readonly<{ a: 0 }> | Readonly<{ a: 1; b: 1 }>
29
- >('=');
30
-
31
- expectType<
32
- HasKeyReturnType<
33
- | Readonly<{ a: 0 }>
34
- | Readonly<{ a: 1; b: 1 }>
35
- | Readonly<{ b: 2 }>
36
- | Readonly<{ c: 3 }>,
37
- 'b'
38
- >,
39
- Readonly<{ a: 1; b: 1 }> | Readonly<{ b: 2 }>
40
- >('=');
41
-
42
- expectType<
43
- HasKeyReturnType<
44
- | ReadonlyRecord<string, number>
45
- | Readonly<{ a: 0 }>
46
- | Readonly<{ a: 1; b: 1 }>
47
- | Readonly<{ b: 2 }>,
48
- 'a'
49
- >,
50
- | Readonly<{ a: 0 }>
51
- | Readonly<{ a: 1; b: 1 }>
52
- | (ReadonlyRecord<'a', number> & ReadonlyRecord<string, number>)
53
- >('=');
54
-
55
- expectType<
56
- HasKeyReturnType<ReadonlyRecord<string, unknown>, 'a'>,
57
- ReadonlyRecord<'a', unknown> & ReadonlyRecord<string, unknown>
58
- >('=');
59
- }
60
-
61
- {
62
- type R = Readonly<{ a: 0 }> | Readonly<{ b: 1 }>;
63
-
64
- const obj: R = { a: 0 } as R;
65
-
66
- if (hasKey(obj, 'a')) {
67
- expectType<typeof obj.a, 0>('=');
68
-
69
- expectType<typeof obj, Readonly<{ a: 0 }>>('=');
70
- }
71
-
72
- if (hasKey(obj, 'c')) {
73
- expectType<typeof obj, never>('=');
74
- }
75
- }
76
-
77
- {
78
- type R =
79
- | Readonly<{ a: 0 }>
80
- | Readonly<{ a: 1; b: 1 }>
81
- | Readonly<{ b: 2 }>
82
- | Readonly<{ c: 3 }>;
83
-
84
- const obj: R = { a: 0 } as R;
85
-
86
- if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
87
- expectType<typeof obj.a, 1>('=');
88
-
89
- expectType<typeof obj.b, 1>('=');
90
-
91
- expectType<typeof obj, Readonly<{ a: 1; b: 1 }>>('=');
92
- }
93
- }
4
+ test('hasKey type inferences', () => {
5
+ {
6
+ expectType<
7
+ HasKeyReturnType<Readonly<{ a: 0 }> | Readonly<{ b: 1 }>, 'a'>,
8
+ Readonly<{ a: 0 }>
9
+ >('=');
94
10
 
95
- {
96
- type R =
97
- | ReadonlyRecord<string, number>
98
- | Readonly<{ a: 0 }>
99
- | Readonly<{ a: 1; b: 1 }>
100
- | Readonly<{ b: 2 }>;
11
+ expectType<
12
+ HasKeyReturnType<Readonly<{ a: 0 }> | Readonly<{ b: 1 }>, 'b'>,
13
+ Readonly<{ b: 1 }>
14
+ >('=');
101
15
 
102
- const obj: R = { a: 0 } as R;
16
+ expectType<
17
+ HasKeyReturnType<Readonly<{ a: 0 }> | Readonly<{ b: 1 }>, 'd'>,
18
+ never
19
+ >('=');
103
20
 
104
- expectType<
105
- R,
106
- | ReadonlyRecord<string, number>
107
- | Readonly<{ a: 0 }>
108
- | Readonly<{ a: 1; b: 1 }>
109
- | Readonly<{ b: 2 }>
110
- >('=');
21
+ expectType<
22
+ HasKeyReturnType<
23
+ | Readonly<{ a: 0 }>
24
+ | Readonly<{ a: 1; b: 1 }>
25
+ | Readonly<{ b: 2 }>
26
+ | Readonly<{ c: 3 }>,
27
+ 'a'
28
+ >,
29
+ Readonly<{ a: 0 }> | Readonly<{ a: 1; b: 1 }>
30
+ >('=');
111
31
 
112
- if (hasKey(obj, 'a')) {
113
- expectType<typeof obj.a, number>('=');
32
+ expectType<
33
+ HasKeyReturnType<
34
+ | Readonly<{ a: 0 }>
35
+ | Readonly<{ a: 1; b: 1 }>
36
+ | Readonly<{ b: 2 }>
37
+ | Readonly<{ c: 3 }>,
38
+ 'b'
39
+ >,
40
+ Readonly<{ a: 1; b: 1 }> | Readonly<{ b: 2 }>
41
+ >('=');
114
42
 
115
43
  expectType<
116
- typeof obj,
44
+ HasKeyReturnType<
45
+ | ReadonlyRecord<string, number>
46
+ | Readonly<{ a: 0 }>
47
+ | Readonly<{ a: 1; b: 1 }>
48
+ | Readonly<{ b: 2 }>,
49
+ 'a'
50
+ >,
117
51
  | Readonly<{ a: 0 }>
118
52
  | Readonly<{ a: 1; b: 1 }>
119
53
  | (ReadonlyRecord<'a', number> & ReadonlyRecord<string, number>)
120
54
  >('=');
121
- }
122
-
123
- if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
124
- expectType<typeof obj.a, number>('=');
125
-
126
- expectType<typeof obj.b, number>('=');
127
55
 
128
56
  expectType<
129
- typeof obj,
130
- | Readonly<{ a: 1; b: 1 }>
131
- | (ReadonlyRecord<'a', number> &
132
- ReadonlyRecord<'b', number> &
133
- ReadonlyRecord<string, number>)
57
+ HasKeyReturnType<ReadonlyRecord<string, unknown>, 'a'>,
58
+ ReadonlyRecord<'a', unknown> & ReadonlyRecord<string, unknown>
134
59
  >('=');
135
60
  }
136
- }
137
61
 
138
- {
139
- const o: ReadonlyRecord<string, unknown> = { a: 0, b: 1 };
62
+ {
63
+ type R = Readonly<{ a: 0 }> | Readonly<{ b: 1 }>;
140
64
 
141
- if (hasKey(o, 'a')) {
142
- expectType<typeof o.a, unknown>('=');
65
+ const obj: R = { a: 0 } as R;
143
66
 
144
- expectType<
145
- typeof o,
146
- ReadonlyRecord<'a', unknown> & ReadonlyRecord<string, unknown>
147
- >('=');
148
- }
67
+ if (hasKey(obj, 'a')) {
68
+ expectType<typeof obj.a, 0>('=');
149
69
 
150
- if (hasKey(o, 'c')) {
151
- expectType<typeof o.c, unknown>('=');
70
+ expectType<typeof obj, Readonly<{ a: 0 }>>('=');
71
+ }
152
72
 
153
- expectType<
154
- typeof o,
155
- ReadonlyRecord<'c', unknown> & ReadonlyRecord<string, unknown>
156
- >('=');
73
+ if (hasKey(obj, 'c')) {
74
+ expectType<typeof obj, never>('=');
75
+ }
157
76
  }
158
77
 
159
- if (hasKey(o, 'a') && hasKey(o, 'b')) {
160
- expectType<typeof o.a, unknown>('=');
78
+ {
79
+ type R =
80
+ | Readonly<{ a: 0 }>
81
+ | Readonly<{ a: 1; b: 1 }>
82
+ | Readonly<{ b: 2 }>
83
+ | Readonly<{ c: 3 }>;
161
84
 
162
- expectType<typeof o.b, unknown>('=');
85
+ const obj: R = { a: 0 } as R;
163
86
 
164
- expectType<
165
- typeof o,
166
- ReadonlyRecord<'a', unknown> &
167
- ReadonlyRecord<'b', unknown> &
168
- ReadonlyRecord<string, unknown>
169
- >('=');
87
+ if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
88
+ expectType<typeof obj.a, 1>('=');
89
+
90
+ expectType<typeof obj.b, 1>('=');
91
+
92
+ expectType<typeof obj, Readonly<{ a: 1; b: 1 }>>('=');
93
+ }
170
94
  }
171
95
 
172
96
  {
173
- /**
174
- * @note Simply using `R & Record<K, R[K]>` as the return type of hasKey may seem good enough
175
- * since it works as intended for cases like `obj: Record<string, unknown>`.
176
- * However, for finite-sized types like `obj: { a: 0 } | { b: 1 }`,
177
- * filtering with `hasKey(obj, 'a')` causes `obj.a` to widen to `unknown` instead of `0`,
178
- * which doesn't work well.
179
- */
180
-
181
- const hasOwnNaive = <R extends UnknownRecord, K extends string>(
182
- obj: R,
183
- key: K,
184
- ): obj is R & Record<K, R[K]> => hasKey(obj, key);
185
-
186
- {
187
- type O =
188
- | Readonly<{ a: 0 }>
189
- | Readonly<{ a: 1; b: 1 }>
190
- | Readonly<{ b: 2 }>
191
- | Record<string, number>;
97
+ type R =
98
+ | ReadonlyRecord<string, number>
99
+ | Readonly<{ a: 0 }>
100
+ | Readonly<{ a: 1; b: 1 }>
101
+ | Readonly<{ b: 2 }>;
192
102
 
193
- const o2 = { b: 2 } as O;
103
+ const obj: R = { a: 0 } as R;
194
104
 
195
- if (hasOwnNaive(o2, 'a')) {
196
- expectType<typeof o2.a, unknown>('=');
197
- }
105
+ expectType<
106
+ R,
107
+ | ReadonlyRecord<string, number>
108
+ | Readonly<{ a: 0 }>
109
+ | Readonly<{ a: 1; b: 1 }>
110
+ | Readonly<{ b: 2 }>
111
+ >('=');
198
112
 
199
- // eslint-disable-next-line no-restricted-syntax
200
- if ('a' in o2) {
201
- expectType<typeof o2.a, number>('=');
202
- }
203
- }
113
+ if (hasKey(obj, 'a')) {
114
+ expectType<typeof obj.a, number>('=');
204
115
 
205
- {
206
- type O =
116
+ expectType<
117
+ typeof obj,
207
118
  | Readonly<{ a: 0 }>
208
119
  | Readonly<{ a: 1; b: 1 }>
209
- | Readonly<{ b: 2 }>;
210
-
211
- const o2 = { b: 2 } as O;
212
-
213
- if (hasOwnNaive(o2, 'a')) {
214
- expectType<typeof o2.a, unknown>('=');
215
- }
216
-
217
- // eslint-disable-next-line no-restricted-syntax
218
- if ('a' in o2) {
219
- expectType<typeof o2.a, 0 | 1>('=');
220
- }
120
+ | (ReadonlyRecord<'a', number> & ReadonlyRecord<string, number>)
121
+ >('=');
221
122
  }
222
123
  }
223
- }
124
+
125
+ assert.strictEqual(true, true);
126
+ });
@@ -38,8 +38,7 @@ import { isNonNullObject } from './is-non-null-object.mjs';
38
38
  * @see {@link isNonNullObject} - For checking any object type (includes arrays)
39
39
  * @see {@link hasKey} - For checking if a record has specific keys
40
40
  */
41
- export const isRecord = (u: unknown): u is UnknownRecord =>
42
- isNonNullObject(u) && !Array.isArray(u);
41
+ export const isRecord = (u: unknown): u is UnknownRecord => isNonNullObject(u);
43
42
 
44
43
  /**
45
44
  * Type guard that checks if a value is a mutable record (an object with mutable string keys).
@@ -2,110 +2,100 @@ import { expectType } from '../expect-type.mjs';
2
2
  import { isRecord } from './is-record.mjs';
3
3
 
4
4
  describe(isRecord, () => {
5
- test('{ x: 1 } is a record', () => {
6
- const obj = { x: 1 } as const;
5
+ describe('arrays are Records', () => {
6
+ test('number[] is assignable to Record<number, unknown>', () => {
7
+ const arr: Record<number, unknown> = [1, 2, 3];
7
8
 
8
- const unk: unknown = obj;
9
+ const unk: unknown = arr;
9
10
 
10
- const res = isRecord(unk);
11
+ assert.isTrue(isRecord(unk));
11
12
 
12
- expectType<typeof obj, UnknownRecord>('<=');
13
+ expectType<typeof unk, UnknownRecord>('<=');
14
+ });
13
15
 
14
- expectType<typeof res, boolean>('=');
16
+ test('string[] is assignable to Record<number, unknown>', () => {
17
+ const arr: Record<number, unknown> = ['1', '2', '3'];
15
18
 
16
- if (res) {
17
- expectType<typeof unk, UnknownRecord>('=');
18
- }
19
+ const unk: unknown = arr;
19
20
 
20
- assert.isTrue(res);
21
- });
22
-
23
- test('{} is a record', () => {
24
- const obj = {} as const;
25
-
26
- const unk: unknown = obj;
21
+ assert.isTrue(isRecord(unk));
27
22
 
28
- const res = isRecord(unk);
23
+ expectType<typeof unk, UnknownRecord>('<=');
24
+ });
29
25
 
30
- expectType<typeof obj, {}>('=');
26
+ test('[] is a record', () => {
27
+ const arr: unknown = [] as const;
31
28
 
32
- expectType<typeof res, boolean>('=');
29
+ const unk: unknown = arr;
33
30
 
34
- if (res) {
35
- expectType<typeof unk, UnknownRecord>('=');
36
- }
31
+ assert.isTrue(isRecord(unk));
37
32
 
38
- assert.isTrue(res);
33
+ expectType<typeof unk, UnknownRecord>('<=');
34
+ });
39
35
  });
40
36
 
41
- test('[] is not a record', () => {
42
- const obj: DeepReadonly<never[]> = [] as const;
43
-
44
- const unk: unknown = obj;
45
-
46
- const res = isRecord(unk);
47
-
48
- expectType<typeof obj, readonly never[]>('=');
37
+ describe('non-null objects are Records', () => {
38
+ test('{ x: 1 } is a record', () => {
39
+ const obj = { x: 1 } as const;
49
40
 
50
- expectType<typeof res, boolean>('=');
41
+ const unk: unknown = obj;
51
42
 
52
- assert.isFalse(res);
53
- });
54
-
55
- test('null is not a record', () => {
56
- const obj = null;
43
+ assert.isTrue(isRecord(unk));
57
44
 
58
- const unk: unknown = obj;
45
+ expectType<typeof unk, UnknownRecord>('<=');
46
+ });
59
47
 
60
- const res = isRecord(unk);
48
+ test('{} is a record', () => {
49
+ const obj = {} as const;
61
50
 
62
- expectType<typeof obj, null>('=');
51
+ const unk: unknown = obj;
63
52
 
64
- expectType<typeof res, boolean>('=');
53
+ assert.isTrue(isRecord(unk));
65
54
 
66
- assert.isFalse(res);
55
+ expectType<typeof unk, UnknownRecord>('<=');
56
+ });
67
57
  });
68
58
 
69
- test('undefined is not a record', () => {
70
- const obj = undefined;
71
-
72
- const unk: unknown = obj;
59
+ describe('primitives are not Records', () => {
60
+ test('null is not a record', () => {
61
+ const obj = null;
73
62
 
74
- const res = isRecord(unk);
63
+ const unk: unknown = obj;
75
64
 
76
- expectType<typeof obj, undefined>('=');
65
+ assert.isFalse(isRecord(unk));
77
66
 
78
- expectType<typeof res, boolean>('=');
67
+ expectType<typeof unk, UnknownRecord>('!<=');
68
+ });
79
69
 
80
- assert.isFalse(res);
81
- });
82
-
83
- test('3 is not a record', () => {
84
- const obj = 3;
70
+ test('undefined is not a record', () => {
71
+ const prm = undefined;
85
72
 
86
- const unk: unknown = obj;
73
+ const unk: unknown = prm;
87
74
 
88
- const res = isRecord(unk);
75
+ assert.isFalse(isRecord(unk));
89
76
 
90
- expectType<typeof obj, 3>('=');
77
+ expectType<typeof unk, UnknownRecord>('!<=');
78
+ });
91
79
 
92
- expectType<typeof res, boolean>('=');
80
+ test('3 is not a record', () => {
81
+ const prm = 3;
93
82
 
94
- assert.isFalse(res);
95
- });
83
+ const unk: unknown = prm;
96
84
 
97
- test('"str" is not a record', () => {
98
- const obj = 'str';
85
+ assert.isFalse(isRecord(unk));
99
86
 
100
- const unk: unknown = obj;
87
+ expectType<typeof unk, UnknownRecord>('!<=');
88
+ });
101
89
 
102
- const res = isRecord(unk);
90
+ test('"str" is not a record', () => {
91
+ const prm = 'str';
103
92
 
104
- expectType<typeof obj, 'str'>('=');
93
+ const unk: unknown = prm;
105
94
 
106
- expectType<typeof res, boolean>('=');
95
+ assert.isFalse(isRecord(unk));
107
96
 
108
- assert.isFalse(res);
97
+ expectType<typeof unk, UnknownRecord>('!<=');
98
+ });
109
99
  });
110
100
 
111
101
  // test('Map is not a record', () => {
@@ -118,11 +118,11 @@ describe('parse', () => {
118
118
  });
119
119
 
120
120
  test('should not throw errors', () => {
121
- expect(() => Json.parse('{{{')).not.toThrow();
121
+ expect(() => Json.parse('{{{')).not.toThrowError();
122
122
 
123
- expect(() => Json.parse('null null')).not.toThrow();
123
+ expect(() => Json.parse('null null')).not.toThrowError();
124
124
 
125
- expect(() => Json.parse(String(undefined))).not.toThrow();
125
+ expect(() => Json.parse(String(undefined))).not.toThrowError();
126
126
  });
127
127
 
128
128
  test('should use reviver function to transform values', () => {
@@ -323,9 +323,9 @@ describe('stringify', () => {
323
323
 
324
324
  mut_circularArray.push(mut_circularArray);
325
325
 
326
- expect(() => Json.stringify(mut_circularArray)).not.toThrow();
326
+ expect(() => Json.stringify(mut_circularArray)).not.toThrowError();
327
327
 
328
- expect(() => Json.stringify({ fn: () => {} })).not.toThrow();
328
+ expect(() => Json.stringify({ fn: () => {} })).not.toThrowError();
329
329
  });
330
330
 
331
331
  test('should use replacer function to filter values', () => {
@@ -6,27 +6,31 @@ import { asNonZeroFiniteNumber } from './non-zero-finite-number.mjs';
6
6
  describe('FiniteNumber test', () => {
7
7
  describe(asFiniteNumber, () => {
8
8
  test('accepts valid finite numbers', () => {
9
- expect(() => asFiniteNumber(0)).not.toThrow();
9
+ expect(() => asFiniteNumber(0)).not.toThrowError();
10
10
 
11
- expect(() => asFiniteNumber(1)).not.toThrow();
11
+ expect(() => asFiniteNumber(1)).not.toThrowError();
12
12
 
13
- expect(() => asFiniteNumber(-1)).not.toThrow();
13
+ expect(() => asFiniteNumber(-1)).not.toThrowError();
14
14
 
15
- expect(() => asFiniteNumber(3.14)).not.toThrow();
15
+ expect(() => asFiniteNumber(3.14)).not.toThrowError();
16
16
 
17
- expect(() => asFiniteNumber(-2.5)).not.toThrow();
17
+ expect(() => asFiniteNumber(-2.5)).not.toThrowError();
18
18
 
19
- expect(() => asFiniteNumber(Number.MAX_VALUE)).not.toThrow();
19
+ expect(() => asFiniteNumber(Number.MAX_VALUE)).not.toThrowError();
20
20
 
21
- expect(() => asFiniteNumber(-Number.MAX_VALUE)).not.toThrow();
21
+ expect(() => asFiniteNumber(-Number.MAX_VALUE)).not.toThrowError();
22
22
  });
23
23
 
24
24
  test('rejects non-finite numbers', () => {
25
- expect(() => asFiniteNumber(Number.NaN)).toThrow(TypeError);
25
+ expect(() => asFiniteNumber(Number.NaN)).toThrowError(TypeError);
26
26
 
27
- expect(() => asFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(TypeError);
27
+ expect(() => asFiniteNumber(Number.POSITIVE_INFINITY)).toThrowError(
28
+ TypeError,
29
+ );
28
30
 
29
- expect(() => asFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
31
+ expect(() => asFiniteNumber(Number.NEGATIVE_INFINITY)).toThrowError(
32
+ TypeError,
33
+ );
30
34
  });
31
35
 
32
36
  test('returns the same value for valid inputs', () => {
@@ -44,7 +48,7 @@ describe('FiniteNumber test', () => {
44
48
  ] as const)(
45
49
  `asFiniteNumber($name) should throw a TypeError`,
46
50
  ({ value }) => {
47
- expect(() => asFiniteNumber(value)).toThrow(
51
+ expect(() => asFiniteNumber(value)).toThrowError(
48
52
  new TypeError(`Expected a finite number, got: ${value}`),
49
53
  );
50
54
  },
@@ -6,31 +6,31 @@ import { asNonZeroInt } from './non-zero-int.mjs';
6
6
  describe('Int test', () => {
7
7
  describe(asInt, () => {
8
8
  test('accepts valid integers', () => {
9
- expect(() => asInt(0)).not.toThrow();
9
+ expect(() => asInt(0)).not.toThrowError();
10
10
 
11
- expect(() => asInt(1)).not.toThrow();
11
+ expect(() => asInt(1)).not.toThrowError();
12
12
 
13
- expect(() => asInt(-1)).not.toThrow();
13
+ expect(() => asInt(-1)).not.toThrowError();
14
14
 
15
- expect(() => asInt(42)).not.toThrow();
15
+ expect(() => asInt(42)).not.toThrowError();
16
16
 
17
- expect(() => asInt(-42)).not.toThrow();
17
+ expect(() => asInt(-42)).not.toThrowError();
18
18
 
19
- expect(() => asInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
19
+ expect(() => asInt(Number.MAX_SAFE_INTEGER)).not.toThrowError();
20
20
 
21
- expect(() => asInt(Number.MIN_SAFE_INTEGER)).not.toThrow();
21
+ expect(() => asInt(Number.MIN_SAFE_INTEGER)).not.toThrowError();
22
22
  });
23
23
 
24
24
  test('rejects non-integers', () => {
25
- expect(() => asInt(Number.NaN)).toThrow(TypeError);
25
+ expect(() => asInt(Number.NaN)).toThrowError(TypeError);
26
26
 
27
- expect(() => asInt(Number.POSITIVE_INFINITY)).toThrow(TypeError);
27
+ expect(() => asInt(Number.POSITIVE_INFINITY)).toThrowError(TypeError);
28
28
 
29
- expect(() => asInt(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
29
+ expect(() => asInt(Number.NEGATIVE_INFINITY)).toThrowError(TypeError);
30
30
 
31
- expect(() => asInt(1.2)).toThrow(TypeError);
31
+ expect(() => asInt(1.2)).toThrowError(TypeError);
32
32
 
33
- expect(() => asInt(-3.4)).toThrow(TypeError);
33
+ expect(() => asInt(-3.4)).toThrowError(TypeError);
34
34
  });
35
35
 
36
36
  test('returns the same value for valid inputs', () => {
@@ -48,7 +48,7 @@ describe('Int test', () => {
48
48
  { name: '1.2', value: 1.2 },
49
49
  { name: '-3.4', value: -3.4 },
50
50
  ] as const)(`asInt($name) should throw a TypeError`, ({ value }) => {
51
- expect(() => asInt(value)).toThrow(
51
+ expect(() => asInt(value)).toThrowError(
52
52
  new TypeError(`Expected an integer, got: ${value}`),
53
53
  );
54
54
  });