Skip to content

Error TS1206: Decorators are not valid here on a non-top level class #8361

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
bcherny opened this issue Apr 28, 2016 · 4 comments
Closed

Error TS1206: Decorators are not valid here on a non-top level class #8361

bcherny opened this issue Apr 28, 2016 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@bcherny
Copy link

bcherny commented Apr 28, 2016

function decorator(container, key) {}

class A {
    @decorator // OK
    fn(){}
}

let a = {
    b: class B {
        @decorator // Error TS1206: Decorators are not valid here
        fn(){}
    }
}

My use case is a controller class in an Angular 1.5 component:

const MyComponent = {
  bindings: {...},
  template: `...`,
  controller: class MyComponentController extends BaseComponent {
    @override
    foo() {...}
  }
}

abstract class BaseComponent {
  protected foo() {...}
}
@mhegazy
Copy link
Contributor

mhegazy commented Apr 28, 2016

duplicate of #8257 and #7342

@mhegazy mhegazy closed this as completed Apr 28, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 28, 2016
@bcherny
Copy link
Author

bcherny commented Apr 28, 2016

@mhegazy I saw both of those issues before filing this one - I think they are different than this.

#8257 is for an instantiated class
#7342 is for anonymous classes
This issue is for non-top level named classes.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 28, 2016

it is neither instantiated nor anonymous that matters. it is class declaration (top level), vs. class expression (everything else). (similar to function declaration, vs function expression.)

@bcherny
Copy link
Author

bcherny commented Apr 28, 2016

Got it - thanks.

@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

2 participants