Last updated: Feb 29, 2024
Reading time·2 min
To solve the error "Experimental support for decorators is a feature that is
subject to change in a future release", make sure to set the
experimentalDecorators
to true
in your tsconfig.json
file and restart your
IDE and development server if necessary.
Here is an example of how the error occurs.
// ⛔️ Error: 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.ts(1219) @sealed class BugReport { type = 'report'; title: string; constructor(t: string) { this.title = t; } } function sealed(constructor: any) { Object.seal(constructor); Object.seal(constructor.prototype); }
experimentalDecorators
enabled in your tsconfig.json
file.Note that this may also be your tsconfig.app.json
file if using Angular, or
whichever config file is used in your build process.
{ "compilerOptions": { "target": "es6", "rootDir": "src", "outDir": "build", "experimentalDecorators": true, // 👈️ must be enabled "emitDecoratorMetadata": true, }, "include": ["src/**/*"], "exclude": ["node_modules"] }
The experimentalDecorators setting enables experimental support for decorators.
If you use the include or files options, make sure the file you use decorators in is included in your project and is being tracked by TypeScript.
If your project uses the exclude
option, make sure your exclude
array does not exclude the file in which you're
using decorators.
exclude
option changes what the include
option finds, effectively filtering out some folders or files from compilation.If TypeScript can't find the file in which you are using decorators, you will
get the error even after enabling experimentalDecorators
.
VSCode often glitches and needs a reboot even after you have set the
experimentalDecorators
option to true
in your
tsconfig.json file.
If you got the error in VSCode, you can use your editor's settings to enable experimental decorators.
To solve the error in VSCode:
CTRL + ,
to open your editor's settings.implicitProjectConfig.experimental
Experimental Decorators
setting.If you use VSCode, you can press CTRL + Shift + P
to open the command palette
and type in typescript version
and click on
TypeScript: Select TypeScript version
and then click Use Workspace version
.
If you don't have TypeScript installed locally in your project, open your terminal in your project's root directory and install it.
npm install -D typescript@latest
Now rerun the steps to be sure your code editor uses the right TypeScript version.
I've also written an article on how to check which version of TypeScript is installed.