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
Allow abstract class for local declarations and expressions #9110
It might make sense according to the same rationale that TypeScript supports other local types. It would be helpful to see a motivating example showing the value of a local abstract class.
I had no real use case, I just wanted to scope the abstract class and its derived types to avoid having global symbols. The workaround was to use a surrounding namespace. It was an artificial sample for a TypeScript talk.
Nevertheless, as local types (for non-abstract classes, interfaces, and enums) are supported, IMO missing support for abstract classes means that this feature is incomplete. Also because the compiler output seems to be correct (without --noEmitOnError) except the mentioned error message.
changed the title [-]"Modifiers cannot appear here" for abstract class in function[/-][+]Allow abstract class for local declarations and expressions[/+]on Jun 13, 2016
I agree this should be supported I was just curious what the actual use case was since the base class cannot escape the function anyway, it's only implementations are going to reside within the same scope which should be fairly narrow. However if you're using the function to avoid polluting the global namespace but want to use an abstract class in your design that seems very reasonable. I've been spending too much time writing external modules...
Activity
aluanhaddad commentedon Jun 13, 2016
Yes it should but it doesn't make a lot of sense to do.
yortus commentedon Jun 13, 2016
It might make sense according to the same rationale that TypeScript supports other local types. It would be helpful to see a motivating example showing the value of a local abstract class.
Note this was sort-of anticipated in the proposal for abstract classes, under the heading "To Be Discussed".
ulrichb commentedon Jun 13, 2016
I had no real use case, I just wanted to scope the abstract class and its derived types to avoid having global symbols. The workaround was to use a surrounding namespace. It was an artificial sample for a TypeScript talk.
Nevertheless, as local types (for non-abstract classes, interfaces, and enums) are supported, IMO missing support for abstract classes means that this feature is incomplete. Also because the compiler output seems to be correct (without
--noEmitOnError) except the mentioned error message.[-]"Modifiers cannot appear here" for abstract class in function[/-][+]Allow abstract class for local declarations and expressions[/+]aluanhaddad commentedon Jun 13, 2016
I agree this should be supported I was just curious what the actual use case was since the base class cannot escape the function anyway, it's only implementations are going to reside within the same scope which should be fairly narrow. However if you're using the function to avoid polluting the global namespace but want to use an abstract class in your design that seems very reasonable. I've been spending too much time writing external modules...
rauschma commentedon Aug 10, 2016
This is a use case for abstract class expressions: implementing mixins via subclass factories.
(I don’t feel 100% confident about the type of
S; there must be a better way to type it.)