You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warning on no constructor and super class constructor taking parameters #6979
Based on reading the linked issue, it sounds like you're depending on a DI framework that reflects over the code to figure out what parameters to pass a constructor. In this case, it's up to you to reflect that behavior in your class one way or another (is static $inject = [...] available to you?).
After shipping for three years with the desirable behavior of "Derived classes with no declared constructors automatically get their base class's constructors", it's not feasible to break everyone and tell them to go manually rewrite their constructors so that users of particular DI frameworks get better warnings in some cases.
It would be very easy to write a no-implicit-constructors TSLint rule if that's the kind of thing you wanted to enforce in your project.
Sorry....my bad. This didn't make sense at all. Of course it shouldn't. Full story:
This comes from an Angular 2 use case. The Parent has some decorators for dependency injection. These aren't picked up by Angular since they aren't exposed by Child. The (ES5) javascript generated is
_super.apply(this, arguments)
...which works fine invocation wise, but not decoration wise.
Ryan Cavanaugh (@RyanCavanaugh) I think a better question would be: can we open up for Angular (and similar) to deduce in runtime the constructor hierarchy and look for decoration metadata in the parent. This currently seems impossible (unless I'm mistaken)
Activity
RyanCavanaugh commentedon Feb 9, 2016
Note that you can't just write
And that the generated code calls super for you:
Based on reading the linked issue, it sounds like you're depending on a DI framework that reflects over the code to figure out what parameters to pass a constructor. In this case, it's up to you to reflect that behavior in your class one way or another (is
static $inject = [...]available to you?).After shipping for three years with the desirable behavior of "Derived classes with no declared constructors automatically get their base class's constructors", it's not feasible to break everyone and tell them to go manually rewrite their constructors so that users of particular DI frameworks get better warnings in some cases.
It would be very easy to write a
no-implicit-constructorsTSLint rule if that's the kind of thing you wanted to enforce in your project.staeke commentedon Feb 9, 2016
Sorry....my bad. This didn't make sense at all. Of course it shouldn't. Full story:
This comes from an Angular 2 use case. The Parent has some decorators for dependency injection. These aren't picked up by Angular since they aren't exposed by Child. The (ES5) javascript generated is
...which works fine invocation wise, but not decoration wise.
staeke commentedon Feb 9, 2016
Ryan Cavanaugh (@RyanCavanaugh) you're so right! Well guessed!
staeke commentedon Feb 9, 2016
Ryan Cavanaugh (@RyanCavanaugh) I think a better question would be: can we open up for Angular (and similar) to deduce in runtime the constructor hierarchy and look for decoration metadata in the parent. This currently seems impossible (unless I'm mistaken)