cli icon indicating copy to clipboard operation
cli copied to clipboard

Make hooks generation more Typescript friendly

Open soullivaneuh opened this issue 5 years ago • 0 comments

Here is a suggestion for the generated hooks service file in order to make it more Typescript friendly:

diff --git a/src/services/test/test.hooks.ts b/src/services/test/test.hooks.ts
index 042f6a0..07857c9 100644
--- a/src/services/test/test.hooks.ts
+++ b/src/services/test/test.hooks.ts
@@ -1,5 +1,6 @@
+import { HooksObject } from "@feathersjs/feathers";
 
-export default {
+const hooks: HooksObject<any> = {
   before: {
     all: [],
     find: [],
@@ -30,3 +31,5 @@ export default {
     remove: []
   }
 };
+
+export default hooks;

Thanks to that disposal, we get benefit of type-checking and IDE completion on the hooks object where the export default notation does not get anything.

Plus, replacing any by our data model spreads it on any hook you define in this object. :+1:

What do you think?

soullivaneuh avatar Jan 24 '21 15:01 soullivaneuh