Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-14 14:47:33 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-18 09:55:11 -0400
commitd8c065817f6483d4791611d624d66ff47efa2f41 (patch)
treeb15f4be30a4d9c5aff2fa86ffaedd4e496e3589a /src/types/misc.d.ts
parent07c8b5547598ec129fa24656871abd0f0b2f54f7 (diff)
downloadliza-d8c065817f6483d4791611d624d66ff47efa2f41.tar.gz
liza-d8c065817f6483d4791611d624d66ff47efa2f41.tar.bz2
liza-d8c065817f6483d4791611d624d66ff47efa2f41.zip
NodeCallback<T, R>: New type to simplify callback declarations
Just trying to reduce some boilerplate. I kept this as a separate commit to illustrate clearly how this type of things is done since we'll have people learning TypeScript. * src/types/misc.ts (NodeCallback<T,R>): New type. * src/server/dapi/TokenedDataApi.ts: Use it. * test/server/dapi/TokenedDataApiTest.ts: Use it.
Diffstat (limited to 'src/types/misc.d.ts')
-rw-r--r--src/types/misc.d.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/types/misc.d.ts b/src/types/misc.d.ts
index 6560f2b..83b11b5 100644
--- a/src/types/misc.d.ts
+++ b/src/types/misc.d.ts
@@ -44,3 +44,13 @@ type NominalType<K, T> = K & { __nominal_type__: T };
* Number of seconds since the Unix epoch (1970-01-01 UTC).
*/
type UnixTimestamp = NominalType<number, 'UnixTimestamp'>;
+
+
+/**
+ * Oldschool NodeJS callback
+ *
+ * We should migrate to promises over time. The purpose of this type is to
+ * reduce the boilerplate of these function definitions, and to clearly
+ * document that this pattern is something that used to be done frequently.
+ */
+type NodeCallback<T, R = void> = ( e: Error | null, result: T | null ) => R;