I'm trying to get a basic decorator example to work in TypeScript without any luck.
I'm constantly seeing the error message:
Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
My tsconfig.json looks as follows (tsconfig in the same folder as index.ts):
{
"compilerOptions": {
"target": "esnext",
"watch": true,
"experimentalDecorators": true,
}
}
This seems to be a pretty popular problem and has been asked multiple times on SO e. g.: Experimental decorators warning in TypeScript compilation
I have tried all the solutions without luck. Also, my problem does not seem to be related to vscode. I get the same error trying to run the file from the shell.
What I've tried so far:
- Restart VC Code
- EmitDecoratorMetaData: true
- Allow experimental decorators as an implicit config in VC Code in VC code
- Set TS version manually
- Create new tsconfig.json
EDIT
index.ts
function f(): any {
console.log("f(): evaluated");
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
console.log("f(): called");
}
}
function g(): any {
console.log("g(): evaluated");
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
console.log("g(): called");
}
}
class C {
@f()
@g()
method() {}
}