GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow abstract class for local declarations and expressions · Issue #9110 · microsoft/TypeScript

Allow abstract class for local declarations and expressions #9110

New issue
Copy link
New issue
Copy link
Closed
Closed
Allow abstract class for local declarations and expressions#9110
Copy link
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
TypeScript 2.0.2

Description

@ulrichb
ulrichb
opened on Jun 12, 2016
Issue body actions

TypeScript Version:

1.8.9 / nightly (1.9.0-dev.20160612-1.0)

Code

(() => {
    // works:
    class SomeClass { }

    // emits "error TS1184: Modifiers cannot appear here":
    abstract class SomeAbstractClass { }
})();

Expected behavior:
It should be possible to define abstract classes within functions just like non-abstract ones.

Reacted by GoToLoop

Activity

  1. aluanhaddad commented on Jun 13, 2016

    @aluanhaddad
    Aluan Haddad (aluanhaddad)
    on Jun 13, 2016
    Contributor
    More actions

    Yes it should but it doesn't make a lot of sense to do.

  2. yortus commented on Jun 13, 2016

    @yortus
    Troy Gerwien (yortus)
    on Jun 13, 2016
    Contributor
    More actions

    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".

  3. ulrichb commented on Jun 13, 2016

    @ulrichb
    ulrichb
    on Jun 13, 2016
    Author
    More actions

    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.

    Reacted by GoToLoop
  4. Mohamed Hegazy (mhegazy)
    changed the title [-]"Modifiers cannot appear here" for abstract class in function[/-] [+]Allow abstract class for local declarations and expressions[/+] on Jun 13, 2016
  5. Mohamed Hegazy (mhegazy)
    added
    SuggestionAn idea for TypeScriptAn idea for TypeScript
    Accepting PRs
    Effort: Easy
    on Jun 13, 2016
  6. Mohamed Hegazy (mhegazy)
    assigned
    ghost
    on Jun 13, 2016
  7. aluanhaddad commented on Jun 13, 2016

    @aluanhaddad
    Aluan Haddad (aluanhaddad)
    on Jun 13, 2016
    Contributor
    More actions

    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...

    Reacted by ulrichb and GoToLoop
  8. ghost closed this as completedin #9994on Jul 28, 2016
  9. rauschma commented on Aug 10, 2016

    @rauschma
    Axel Rauschmayer (rauschma)
    on Aug 10, 2016
    More actions

    This is a use case for abstract class expressions: implementing mixins via subclass factories.

    const MyMixin = (S : { new () : Object }) => abstract class extends S {
        abstract foo() {}
        bar() {}
    };
    
    // Must implement foo()
    class MyClass extends MyMixin(Object) {
    }

    (I don’t feel 100% confident about the type of S; there must be a better way to type it.)

  10. Mohamed Hegazy (mhegazy)
    added this to the This milestone has been deleted milestone on Aug 17, 2016
  11. Mohamed Hegazy (mhegazy)
    added
    FixedA PR has been merged for this issueA PR has been merged for this issue
    on Aug 17, 2016
  12. microsoft
    locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      • TypeScript 2.0.2

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.