@reykjavik/webtools 0.3.3 → 0.3.5

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/CHANGELOG.md CHANGED
@@ -4,11 +4,26 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.3.5
8
+
9
+ _2026-02-18_
10
+
11
+ - fix: `Result.ErrorOf<T>` not handling functions with parameters correctly
12
+
13
+ ## 0.3.4
14
+
15
+ _2026-02-17_
16
+
17
+ - `@reykjavik/webtools/errorhandling`:
18
+ - feat: Add type `Result.ErrorOf<T>` to extract the error type of a
19
+ `ResultTuple<T>` or a `ResultTuple`-returning function
20
+
7
21
  ## 0.3.3
8
22
 
9
23
  _2026-02-13_
10
24
 
11
- - feat: Make `ResultFail` better infer its error type from the argument
25
+ - `@reykjavik/webtools/errorhandling`:
26
+ - feat: Make `ResultFail` better infer its error type from the argument
12
27
 
13
28
  ## 0.3.2
14
29
 
@@ -16,7 +31,7 @@ _2025-12-01_
16
31
 
17
32
  - `@reykjavik/webtools/errorhandling`:
18
33
  - feat: Add type `Result.PayloadOf<T>` to extract the successful payload
19
- type from a `ResultTuple<T>` or a `ResultTuple`-returning function
34
+ type from a `ResultTuple<T>` or a `ResultTuple`-returning functions
20
35
 
21
36
  ## 0.3.0 – 0.3.1
22
37
 
package/README.md CHANGED
@@ -47,6 +47,7 @@ bun add @reykjavik/webtools
47
47
  - [`Result.Fail`](#resultfail)
48
48
  - [`Result.throw`](#resultthrow)
49
49
  - [Type `Result.PayloadOf`](#type-resultpayloadof)
50
+ - [Type `Result.ErrorOf`](#type-resulterrorof)
50
51
  - [`@reykjavik/webtools/SiteImprove`](#reykjavikwebtoolssiteimprove)
51
52
  - [`SiteImprove` component](#siteimprove-component)
52
53
  - [`pingSiteImprove` helper](#pingsiteimprove-helper)
@@ -864,6 +865,32 @@ type Payload4 = Result.PayloadOf<ResTplPromiseFn>; // Date
864
865
 
865
866
  ---
866
867
 
868
+ ### Type `Result.ErrorOf`
869
+
870
+ **Syntax:**
871
+ `Result.ErrorOf<T extends | ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)>`
872
+
873
+ This utility type extracts the error type `E` from a `Result.Tuple<T>`-like
874
+ type, a `Promise` of such type, or a function returning either of those.
875
+
876
+ ```ts
877
+ import { Result } from '@reykjavik/webtools/errorhandling';
878
+
879
+ type ResTpl = Result.Tuple<string, RangeError>;
880
+ type ResTplPromise = Promise<Result.Tuple<number, RangeError>>;
881
+ type ResTplFn = (arg: unknown) => Result.Tuple<boolean, RangeError>;
882
+ type ResTplPromiseFn = (
883
+ arg: unknown
884
+ ) => Promise<Result.Tuple<Date, RangeError>>;
885
+
886
+ type Error1 = Result.ErrorOf<ResTpl>; // RangeError
887
+ type Error2 = Result.ErrorOf<ResTplPromise>; // RangeError
888
+ type Error3 = Result.ErrorOf<ResTplFn>; // RangeError
889
+ type Error4 = Result.ErrorOf<ResTplPromiseFn>; // RangeError
890
+ ```
891
+
892
+ ---
893
+
867
894
  ## `@reykjavik/webtools/SiteImprove`
868
895
 
869
896
  Contains React helpers for loading SiteImprove's analytics scripts, and
@@ -115,5 +115,62 @@ export declare namespace Result {
115
115
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
116
116
  */
117
117
  type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
118
+ /**
119
+ * Extracts the error type `E` from a `Result.Tuple<T, E>`-like
120
+ * type, a `Promise` of such type, or a function returning either of those.
121
+ *
122
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
123
+ */
124
+ type ErrorOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [infer E, undefined?] ? E : T extends Promise<infer P> ? P extends [infer E, undefined?] ? E : never : T extends (...args: Array<any>) => infer R ? R extends [infer E, undefined?] ? E : R extends Promise<infer P> ? P extends [infer E, undefined?] ? E : never : never : never;
118
125
  }
119
126
  export {};
127
+ /** /
128
+ // ---------------------------------------------------------------------------
129
+ // Tests for the Result.ErrorOf type helper:
130
+ // Should all extract the `X_Error` type as the error type from the various `Result.Tuple`-like types below:
131
+ let _e1: Result.ErrorOf<Result.Tuple<P, X_Error>>;
132
+ // ^?
133
+ let _e2: Result.ErrorOf<Result.TupleObj<P, X_Error>>;
134
+ // ^?
135
+ let _e3: Result.ErrorOf<ResultTupleObj<P, X_Error>>;
136
+ // ^?
137
+ let _e4: Result.ErrorOf<ResultTuple<P, X_Error>>;
138
+ // ^?
139
+
140
+ let _e5: Result.ErrorOf<Promise<Result.Tuple<P, X_Error>>>;
141
+ // ^?
142
+ let _e6: Result.ErrorOf<Promise<Result.TupleObj<P, X_Error>>>;
143
+ // ^?
144
+ let _e7: Result.ErrorOf<Promise<ResultTuple<P, X_Error>>>;
145
+ // ^?
146
+ let _e8: Result.ErrorOf<Promise<ResultTupleObj<P, X_Error>>>;
147
+ // ^?
148
+
149
+ let _E1: Result.ErrorOf<() => Result.Tuple<P, X_Error>>;
150
+ // ^?
151
+ let _E2: Result.ErrorOf<() => Result.TupleObj<P, X_Error>>;
152
+ // ^?
153
+ let _E3: Result.ErrorOf<() => ResultTupleObj<P, X_Error>>;
154
+ // ^?
155
+ let _E3b: Result.ErrorOf<(a: null) => ResultTupleObj<P, X_Error>>;
156
+ // ^?
157
+ let _E4: Result.ErrorOf<() => ResultTuple<P, X_Error>>;
158
+ // ^?
159
+
160
+ let _E5: Result.ErrorOf<() => Promise<Result.Tuple<P, X_Error>>>;
161
+ // ^?
162
+ let _E6: Result.ErrorOf<() => Promise<Result.TupleObj<P, X_Error>>>;
163
+ // ^?
164
+ let _E7: Result.ErrorOf<() => Promise<ResultTuple<P, X_Error>>>;
165
+ // ^?
166
+ let _E8: Result.ErrorOf<() => Promise<ResultTupleObj<P, X_Error>>>;
167
+ // ^?
168
+
169
+ type P = string;
170
+ class X_Error extends Error {
171
+ skilabod = 'fooo';
172
+ constructor() {
173
+ super('FormData validation error');
174
+ }
175
+ }
176
+ /**/
package/errorhandling.js CHANGED
@@ -126,3 +126,53 @@ exports.Result = {
126
126
  return result[1];
127
127
  },
128
128
  };
129
+ /** /
130
+ // ---------------------------------------------------------------------------
131
+ // Tests for the Result.ErrorOf type helper:
132
+ // Should all extract the `X_Error` type as the error type from the various `Result.Tuple`-like types below:
133
+ let _e1: Result.ErrorOf<Result.Tuple<P, X_Error>>;
134
+ // ^?
135
+ let _e2: Result.ErrorOf<Result.TupleObj<P, X_Error>>;
136
+ // ^?
137
+ let _e3: Result.ErrorOf<ResultTupleObj<P, X_Error>>;
138
+ // ^?
139
+ let _e4: Result.ErrorOf<ResultTuple<P, X_Error>>;
140
+ // ^?
141
+
142
+ let _e5: Result.ErrorOf<Promise<Result.Tuple<P, X_Error>>>;
143
+ // ^?
144
+ let _e6: Result.ErrorOf<Promise<Result.TupleObj<P, X_Error>>>;
145
+ // ^?
146
+ let _e7: Result.ErrorOf<Promise<ResultTuple<P, X_Error>>>;
147
+ // ^?
148
+ let _e8: Result.ErrorOf<Promise<ResultTupleObj<P, X_Error>>>;
149
+ // ^?
150
+
151
+ let _E1: Result.ErrorOf<() => Result.Tuple<P, X_Error>>;
152
+ // ^?
153
+ let _E2: Result.ErrorOf<() => Result.TupleObj<P, X_Error>>;
154
+ // ^?
155
+ let _E3: Result.ErrorOf<() => ResultTupleObj<P, X_Error>>;
156
+ // ^?
157
+ let _E3b: Result.ErrorOf<(a: null) => ResultTupleObj<P, X_Error>>;
158
+ // ^?
159
+ let _E4: Result.ErrorOf<() => ResultTuple<P, X_Error>>;
160
+ // ^?
161
+
162
+ let _E5: Result.ErrorOf<() => Promise<Result.Tuple<P, X_Error>>>;
163
+ // ^?
164
+ let _E6: Result.ErrorOf<() => Promise<Result.TupleObj<P, X_Error>>>;
165
+ // ^?
166
+ let _E7: Result.ErrorOf<() => Promise<ResultTuple<P, X_Error>>>;
167
+ // ^?
168
+ let _E8: Result.ErrorOf<() => Promise<ResultTupleObj<P, X_Error>>>;
169
+ // ^?
170
+
171
+ type P = string;
172
+ class X_Error extends Error {
173
+ skilabod = 'fooo';
174
+ constructor() {
175
+ super('FormData validation error');
176
+ }
177
+ }
178
+ /**/
@@ -115,5 +115,62 @@ export declare namespace Result {
115
115
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
116
116
  */
117
117
  type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
118
+ /**
119
+ * Extracts the error type `E` from a `Result.Tuple<T, E>`-like
120
+ * type, a `Promise` of such type, or a function returning either of those.
121
+ *
122
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
123
+ */
124
+ type ErrorOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [infer E, undefined?] ? E : T extends Promise<infer P> ? P extends [infer E, undefined?] ? E : never : T extends (...args: Array<any>) => infer R ? R extends [infer E, undefined?] ? E : R extends Promise<infer P> ? P extends [infer E, undefined?] ? E : never : never : never;
118
125
  }
119
126
  export {};
127
+ /** /
128
+ // ---------------------------------------------------------------------------
129
+ // Tests for the Result.ErrorOf type helper:
130
+ // Should all extract the `X_Error` type as the error type from the various `Result.Tuple`-like types below:
131
+ let _e1: Result.ErrorOf<Result.Tuple<P, X_Error>>;
132
+ // ^?
133
+ let _e2: Result.ErrorOf<Result.TupleObj<P, X_Error>>;
134
+ // ^?
135
+ let _e3: Result.ErrorOf<ResultTupleObj<P, X_Error>>;
136
+ // ^?
137
+ let _e4: Result.ErrorOf<ResultTuple<P, X_Error>>;
138
+ // ^?
139
+
140
+ let _e5: Result.ErrorOf<Promise<Result.Tuple<P, X_Error>>>;
141
+ // ^?
142
+ let _e6: Result.ErrorOf<Promise<Result.TupleObj<P, X_Error>>>;
143
+ // ^?
144
+ let _e7: Result.ErrorOf<Promise<ResultTuple<P, X_Error>>>;
145
+ // ^?
146
+ let _e8: Result.ErrorOf<Promise<ResultTupleObj<P, X_Error>>>;
147
+ // ^?
148
+
149
+ let _E1: Result.ErrorOf<() => Result.Tuple<P, X_Error>>;
150
+ // ^?
151
+ let _E2: Result.ErrorOf<() => Result.TupleObj<P, X_Error>>;
152
+ // ^?
153
+ let _E3: Result.ErrorOf<() => ResultTupleObj<P, X_Error>>;
154
+ // ^?
155
+ let _E3b: Result.ErrorOf<(a: null) => ResultTupleObj<P, X_Error>>;
156
+ // ^?
157
+ let _E4: Result.ErrorOf<() => ResultTuple<P, X_Error>>;
158
+ // ^?
159
+
160
+ let _E5: Result.ErrorOf<() => Promise<Result.Tuple<P, X_Error>>>;
161
+ // ^?
162
+ let _E6: Result.ErrorOf<() => Promise<Result.TupleObj<P, X_Error>>>;
163
+ // ^?
164
+ let _E7: Result.ErrorOf<() => Promise<ResultTuple<P, X_Error>>>;
165
+ // ^?
166
+ let _E8: Result.ErrorOf<() => Promise<ResultTupleObj<P, X_Error>>>;
167
+ // ^?
168
+
169
+ type P = string;
170
+ class X_Error extends Error {
171
+ skilabod = 'fooo';
172
+ constructor() {
173
+ super('FormData validation error');
174
+ }
175
+ }
176
+ /**/
@@ -121,3 +121,53 @@ export const Result = {
121
121
  return result[1];
122
122
  },
123
123
  };
124
+ /** /
125
+ // ---------------------------------------------------------------------------
126
+ // Tests for the Result.ErrorOf type helper:
127
+ // Should all extract the `X_Error` type as the error type from the various `Result.Tuple`-like types below:
128
+ let _e1: Result.ErrorOf<Result.Tuple<P, X_Error>>;
129
+ // ^?
130
+ let _e2: Result.ErrorOf<Result.TupleObj<P, X_Error>>;
131
+ // ^?
132
+ let _e3: Result.ErrorOf<ResultTupleObj<P, X_Error>>;
133
+ // ^?
134
+ let _e4: Result.ErrorOf<ResultTuple<P, X_Error>>;
135
+ // ^?
136
+
137
+ let _e5: Result.ErrorOf<Promise<Result.Tuple<P, X_Error>>>;
138
+ // ^?
139
+ let _e6: Result.ErrorOf<Promise<Result.TupleObj<P, X_Error>>>;
140
+ // ^?
141
+ let _e7: Result.ErrorOf<Promise<ResultTuple<P, X_Error>>>;
142
+ // ^?
143
+ let _e8: Result.ErrorOf<Promise<ResultTupleObj<P, X_Error>>>;
144
+ // ^?
145
+
146
+ let _E1: Result.ErrorOf<() => Result.Tuple<P, X_Error>>;
147
+ // ^?
148
+ let _E2: Result.ErrorOf<() => Result.TupleObj<P, X_Error>>;
149
+ // ^?
150
+ let _E3: Result.ErrorOf<() => ResultTupleObj<P, X_Error>>;
151
+ // ^?
152
+ let _E3b: Result.ErrorOf<(a: null) => ResultTupleObj<P, X_Error>>;
153
+ // ^?
154
+ let _E4: Result.ErrorOf<() => ResultTuple<P, X_Error>>;
155
+ // ^?
156
+
157
+ let _E5: Result.ErrorOf<() => Promise<Result.Tuple<P, X_Error>>>;
158
+ // ^?
159
+ let _E6: Result.ErrorOf<() => Promise<Result.TupleObj<P, X_Error>>>;
160
+ // ^?
161
+ let _E7: Result.ErrorOf<() => Promise<ResultTuple<P, X_Error>>>;
162
+ // ^?
163
+ let _E8: Result.ErrorOf<() => Promise<ResultTupleObj<P, X_Error>>>;
164
+ // ^?
165
+
166
+ type P = string;
167
+ class X_Error extends Error {
168
+ skilabod = 'fooo';
169
+ constructor() {
170
+ super('FormData validation error');
171
+ }
172
+ }
173
+ /**/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
5
5
  "main": "index.js",
6
6
  "repository": "ssh://git@github.com:reykjavikcity/webtools.git",