Decorators must precede the name and all keywords of property declarations

Viewed 326

I created a decorator called @Inject in typescript file, like this

export class A{
    @Inject()
    private b!: string

    @Inject()
    private c!: string
}

But vscode told me there was a mistake

export class A{
    @Inject()
    private b!: string

    @Inject() //error : Decorators must precede the name and all keywords of property declarations.
    private c!: string
}

But when I execute the TSC command, the terminal does not display any errors.

The strangest thing is that when I end with a semicolon, the error disappears.

export class A{
    @Inject()
    private b!: string ;

    @Inject()
    private c!: string ;
}
2 Answers

you must to change version typescript in visual studio code. for me version typescript is 4.3.2

You need to search after your Typescript version and change it to your current workspace version instead of the vscode typescript version which is currently a dev verison.

First search after >Typescript: Version

enter image description here

Than you can selest the current workspace verison

enter image description here

You also can click on the bottom right corner on the typscript version and change it to your current workspace version.

Related