Skip to content

error TS1206: Decorators are not valid here? #3661

Closed

Description

Hi,

What's the problem here? I can't see it.

@Provide(Log)
function getKarmaLoggerInstance() {
    return logger.create('preprocessor-x');
}

This produces the following compiler error:

error TS1206: Decorators are not valid here.

My only guess is that it's on a function, but aren't decorators supposed to be applicable to functions?

Activity

  1. DanielRosenwasser commented on Jun 29, 2015

    @DanielRosenwasser
    Member

    Decorators are not supported on function declarations. To quote #2249:

    • Decorating a function declaration is not allowed as it will block hoisting the function to the top of the scope, which is a significant change in semantics.
    • Decorating function expressions and arrow functions are not supported. The same effect can be achived by applying the decorator function as var x = dec(function () { });
    • Decorating function formal parameters is currently not part of the ES7 proposal.
  2. thariesl commented on Feb 9, 2018

    @thariesl

    If somebody still gets this error after the solutions above:

    This was my code:
    @Effect() constructor(private httpClient: HttpClient, private actions$: Actions, private store: Store<fromRecipe.FeatureState>){ } recipeFetch = this.actions$ .ofType(fromRecipe.FETCH_RECIPES) .switchMap((action: fromRecipe.FetchRecipes) => { return this.httpClient.get<Recipe[]>('https://https://course-recipe-book.firebaseio.com/recipes.json', { observe: 'body', responseType: 'json' }) })
    and i got the Error: "Decorators are not valid here.

    afterwards i simply wrote Pavel Fedotov (@effect)() after the constructor above recipeFetch :)
    Worked for me.

  3. locked and limited conversation to collaborators on Jul 3, 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

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions