Skip to content

Decorators within mixins #14607

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

Closed
eb2501 opened this issue Mar 12, 2017 · 8 comments
Closed

Decorators within mixins #14607

eb2501 opened this issue Mar 12, 2017 · 8 comments
Labels
Duplicate An existing issue was already created

Comments

@eb2501
Copy link

eb2501 commented Mar 12, 2017

I wonder if there's any plans to support decorators within mixins?

  type Constructor<T> = { new (...args: any[]): T }

  function Mixin<T extends Constructor<{}>>(Base : T) {
    return class extends Base {
      constructor(...args: any[]) {
        super(...args)
      }

      @decorator
      get y() {
        return this.x + 3
      }
  }

TSC 2.2.1 currently rejects this construction: [Decorators are not valid here]

@Hotell
Copy link

Hotell commented Mar 12, 2017

We got into same issues here https://github.com/wc-catalogue/blaze-elements/blob/master/packages/common/mixins.ts#L10

the quickfix is easy just define the mixin class and return it afterwards:

  type Constructor<T> = { new (...args: any[]): T }

  function Mixin<T extends Constructor<{}>>(Base : T) {
    class MixinClass extends Base {
      constructor(...args: any[]) {
        super(...args)
      }

      @decorator
      get y() {
        return this.x + 3
      }
    }
  
    return MixinClass;
}

@eb2501
Copy link
Author

eb2501 commented Mar 12, 2017

Ah, Wonderful!

Thanks!

@eb2501 eb2501 closed this as completed Mar 12, 2017
@Hotell
Copy link

Hotell commented Mar 12, 2017

Hmm I would rather keep it open to get core team opinion on this cc @RyanCavanaugh @DanielRosenwasser - if it's desing limitation or bug.
What I suggested is just "hotfix" to not get stuck

thx!

@eb2501 eb2501 reopened this Mar 12, 2017
@eb2501
Copy link
Author

eb2501 commented Mar 12, 2017

True.

@aluanhaddad
Copy link
Contributor

See #7342

@DanielRosenwasser
Copy link
Member

I think the idea that decorators can inform the type system of changes that it may be performing is something we will be considering over time.

@Hotell
Copy link

Hotell commented Mar 12, 2017

Cool so I guess we can close this and reference the hotfix to #7342 ?

@DanielRosenwasser
Copy link
Member

Sorry, I misread this. My previous comment has nothing to do with this, but yeah, looks like #7432 seems like the right place to discuss the issue.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Mar 12, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants