Experimental decorators warning in TypeScript comp

2019-01-10 10:55发布

问题:

I have

Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option `to remove this warning.

even my compilerOptions in tsconfig.json have settings:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

What is weird that some random classes that use decorators does not show that warning but rest in same project does.

What could cause such behaviorof the TypeScript compiler?

回答1:

Although VS Code is a great editor for TypeScript projects, it needs a kick every now and again. Often, without warning, certain files cause it to freak out and complain. Mostly the fix seems to be to save and close all open files, then open tsconfig.json. After that you should be able to re-open the offending file without error. If it doesn't work, lather, rinse, and repeat.

If your tsconfig.json specifies its source files using the files array, IntelliSense will only function correctly if the file in question is referenced such that VS Code can find it by traversing the input file tree.

Edit: The 'reload window' command (added ages ago now) should solve this problem once and for all.



回答2:

I've to add the following in the settings.json file of vscode to remove the warning.

"javascript.implicitProjectConfig.experimentalDecorators": true

VSCode -> Preferences -> Settings



回答3:

This error also occurs when you choose "src" folder for your workspace folder.

When the root folder, folder where the "src", "node_modules" are located is chosen, the error disappears



回答4:

have to add typescript.tsdk to my .vscode/settings.json:

"typescript.tsdk": "node_modules/typescript/lib"


回答5:

inside your project create file tsconfig.json , then add this lines

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "allowJs": true
    }
}


回答6:

Open settings.json file in the following location <project_folder>/.vscode/settings.json

or you can open the file from the menu as mentioned below

VSCode -> File -> Preferences -> Workspace Settings

Then add the following lines in settings.json file

{
    "typescript.tsdk": "node_modules/typescript/lib",
    "enable_typescript_language_service": false
}

That's all. You will see no warning/error regarding 'experimentalDecorators'



回答7:

"javascript.implicitProjectConfig.experimentalDecorators": true

Will solve this problem.



回答8:

This answer is intended for people who are using a Javascript project and not a Typescript one. Instead of a tsconfig.json file you may use a jsconfig.json file.

In the particular case of having the decorators warning you wan write inside the file:

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

Fort the buggy behaviors asked, it's always better to specify the "include" in the config file, and restart the editor. E.g.

{
    "compilerOptions": {
        "target": "ES6",
        "experimentalDecorators": true
    },
    "include": [
        "app/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}


回答9:

Not to belabor the point but be sure to add the following to

  • Workspace Settings not User Settings

under File >> Preferences >> Settings

"javascript.implicitProjectConfig.experimentalDecorators": true

this fixed the issue for me, and i tried quite a few suggestions i found here and other places.



回答10:

For the sake of clarity and stupidity.

1) Open .vscode/settings.json.

2) Add "typescript.tsdk": "node_modules/typescript/lib" on it.

3) Save it.

4) Restart Visual Studio Code.



回答11:

Add following lines in tsconfig.json and restart VS Code.

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "target": "es5",
        "allowJs": true
    }
}


回答12:

If you are working in Visual studio. You can try this fix

  1. Unload your project from visual studio
  2. Go to your project home directory and Open "csproj" file.
  3. Add TypeScriptExperimentalDecorators to this section as shown in image

    1. Reload the project in Visual studio.

see more details at this location.



回答13:

I corrected the warning by removing "baseUrl": "", from the tsconfig.json file



回答14:

Open entire project's folder instead of project-name/src

tsconfig.json is out of src folder



回答15:

  1. Open VScode.
  2. Press ctrl+comma
  3. Follow the directions in the screen shot
    1. Search about experimentalDecorators
    2. Edit it


回答16:

Please check you oppened in your VS Code the folder of the entire project and not only the src folder, because if you open only the src, then ts.config.json (located in the project folder) file will not be in scope, and VS will not recognize the experimental decorators parameters.

In my case this fixed all the problems related to this issue.



回答17:

You might run into this issue if you open a TS file that exists outside of the project. For instance, I'm using lerna and had a file open from another package. Although that other package had it's own tsconfig with experimental decorators, VsCode doesn't honor it.



回答18:

I faced the same issue while creating an Injectable Services in Angular 2. I have all the things at place in tsconfig.json .Still I was getting this error at ColorsImmutable line.

@Injectable()
export class ColorsImmutable {

And fix was to register the Service at module Level or Component Level using the providers array.

providers:[ColorsImmutable ],


回答19:

I added this option to tsconfig.json, "baseUrl": "front-end" Replace front-end with the name of your angular-cli project.



回答20:

If you are using cli to compile *.ts files, you can set experimentalDecorators using the following command:

 tsc filename.ts --experimentalDecorators "true"


回答21:

I had this problem recently under Visual Studio 2017 - turned out it was caused by a "feature" of VS - ignoring tsconfig.json when Build action is not set to Content.

So changing the Build action to Content and reloading the solution solved the problem.