-
-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update types for Typescript - fixed GenericObject #600
Conversation
Current GenericObject makes a lot of trouble when using Moleculer with Typescript. Extending it allows any property on interface, but we are using Typescript because we want to use strict types.
#599 ? |
Pull Request Test Coverage Report for Build 2100
💛 - Coveralls |
@kthompson23 @shawnmcknight what are your opinions? |
I'd be interested in hearing more of a rationale on this as well as if #599 possibly solved that scenario. Can you provide any more details @ipetrovic11 ? I am in agreement that in many places the use of Additionally, the reasons I disliked |
I agree with @shawnmcknight but would like to hear more about the rationale behind this change. Sometimes if a type is too restrictive to begin with it's hard to extend but like Shawn said GenericObject is very loose to begin with |
@shawnmcknight @kthompson23 @icebob On our project we are using "strict" mode in ts-config, which is what triggered the issue at the beginning and it doesn't feel like that is bade use case. We want to be sure which types/interfaces we are working with. Error leads to: Since it is defined as Context, it leads to Context<GenericObject, GenericObject> which is where incompatibility is actually happening. And it is not with those types that use Pick, Omit or Partial, it is with any interface that we define. Or this could be other possible solution: |
I was trying to figure out why we have not run into a similar issue as we also type all our params and meta for With that said, I understand the desire to have things as strict as possible so I wouldn't suggest that the answer is "turn off that setting".
In looking at this, I couldn't figure out why it would solve the problem. Your parameter type is not provably compatible with either the index signature or empty object. I tried making my version of The ideal solution to this problem would be to eliminate the defaults for the generics in So with all that said, although it feels a little off to me, I think the solution I'd recommend is that where the |
@shawnmcknight that was just haste comment, that made things work for me while I was in watch mode for a moment. Switching ActionHandler params to Looking further at types definitions not sure how much benefits we have from this class definition: |
So any conclusion? |
@icebob About current issue I would got with improvement on Context definition: |
In 0.14 the This was done specifically to essentially force TS developers to provide type definitions. In hindsight, I would have recommended this change actually be: With that in mind, I'd be very hesitant to recommend allowing I'm still good with changing the |
Current GenericObject makes a lot of trouble when using Moleculer with Typescript.
Extending it allows any property on interface, but we are using Typescript because we want to use strict types.
📝 Description
💎 Type of change