TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

whole function body flagged as error in VS 2015 when class function declared as async

Open rostacik opened this issue 11 years ago • 3 comments

Hello gents. I have the following issue : once a function of a class is declared as async, I see it all underscored red in VS 2015 as if it was one big error. However if I compile this code with typescript@next nightly package, I have no error as result.

I was also able to identify that if I only declare the very same code as function in a module, only function name gets underscored.

This is what I see in my VS 2015 (all latest public updates applied): class functions

Sample code/VS project used for screenshots can be found here https://github.com/rostacik/ts-async-vs-errors

I am also getting this error when I compile the code (via standard VS msbuild chain also with latest TS1.6 beta package) in my Error list window Error TS1236 Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning. However as you can see in the repo, there is tsconfig.json that NodeJS tsc package is accepting.

Small sidenote - I have also typescript@nightly as global package and point to typescriptServices.js as described here : https://github.com/Microsoft/TypeScript/wiki/Dev-Mode-in-Visual-Studio

Thanks in advance for your help.

rostacik avatar Sep 03 '15 15:09 rostacik

Your tsconfig.json should read:

{
  "compilerOptions": {
    "target": "ES6",
    "experimentalAsyncFunctions": true
  }
}

weswigham avatar Sep 03 '15 19:09 weswigham

In your project file, add a property TypeScriptExperimentalAsyncFunctions

<TypeScriptExperimentalAsyncFunctions>true</TypeScriptExperimentalAsyncFunctions>

Full list of property names can be found at: https://github.com/Microsoft/TypeScript/wiki/Setting-Compiler-Options-in-MSBuild-projects

mhegazy avatar Sep 03 '15 20:09 mhegazy

Thank you gents, second option did the trick. Seems like VS is ignoring tsconfig.json as such in its editor.

rostacik avatar Sep 03 '15 21:09 rostacik