Use stricter type for HookContext 'method' prop#1896
Conversation
|
What about custom methods? |
|
This only affects the TypeScript type definitions for a hook's I'm unsure whether |
|
I added support for custom methods with this PR, it is something common and that I do very often. I do not use TypeScript and I am embarrassed to have to overload the type definition in all my projects. |
|
Oh, very cool. I was not aware of that. 👀 This should only affect TypeScript projects, so assuming you're not using TypeScript, no action should be necessary. 👍 If you are using TypeScript, you'll only get a compile warning. Your project should still compile and run as before. |
|
I'll look into automatically incorporating custom method names into the type definition here. 👍 |
|
It does not affect me directly. My IDE, IntelliJ IDEA, will use these types and maybe show me warnings, we'll see. |
|
I had a closer look at the type definitions for services; the current type definitions have limited support for custom methods. Opting for the It's likely going to end up taking a pretty serious refactor to Feathers' service type definitions to properly support inferred custom service methods. While it'd be a pretty good productivity boost for most TypeScript users, this is unfortunately not something I would be able to take responsibility for at the moment. |

A simple tweak to the HookContext's
methodproperty type declaration. This specifies a union type with the possible string types for themethodproperty. Essentially allowing for autocompletes by the IDEs that support TypeScript, as well as warnings should you mistype a method name.