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:
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() {}
}
I noticed that VS Code has an option in the settings to enable experimentalDecorators
for files not a part of a project. Are your code files a part of your project?
You can remove the warning from the CLI with the flag explicitly provided to the command line:
tsc index.ts --experimentalDecorators
An alternative is to list the index.ts
in the files
section of the tsconfig
.
{
"files": ["index.ts"],
"compilerOptions": {
"target": "esnext",
"experimentalDecorators": true
}
}
You can call the CLI without any arguments and it should run without errors.
tsc
I didn't manage to reproduce the error in VS Code though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With