static property inheritance complaining when it shouldn't
See original GitHub issueI’ve seen that you’ve already closed many issues on this. But I’m reporting another one in hopes to wear you down 😉
It seems I can’t change the signature of a static function in a derived class. The fact that the subclass is at all aware of the static functions on the super class is really strange.
I developed in C# for years, so I know what you were trying to do… but given that you don’t support a new
keyword like C# does, I think this behavior is really wrong. If you’re looking to target being a superset of ES6/ES7, you need to correct this behavior ASAP. Generally in JavaScript, static properties are not copied to subclasses unless the copy is explicit.
I ran into this issue with RxJS Next, where I Subject must inherit from Observable, but they both need different static create()
signatures. So I end up hacking around and fighting TypeScript.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:18
- Comments:21 (7 by maintainers)
Top GitHub Comments
So… and now there a plans to change this? I mean, this is pretty old now? Plans for a survey or something?
Static factory methods are a useful design paradigm, for instance when object creation relies on data that needs to be asynchronously fetched a static
create()
method can encapsulate the data fetching, and return the object type (as such fetches cannot be conducted directly in the constructor). This behaviour also aligns with the OOP principles in the popular object oriented languages C# and Java. Requiring that in inheritance each static method with the same name must have compatible types restricts this significantly (forcreate()
, this would enforce the use of the same parameters). Is there an argument for maintaining this restriction?For example, consider the following: