TypeScript in Visual Studio 2017: Automatic definition inclusion causes Duplicate Identifier errors TypeScript in Visual Studio 2017: Automatic definition inclusion causes Duplicate Identifier errors typescript typescript

TypeScript in Visual Studio 2017: Automatic definition inclusion causes Duplicate Identifier errors


I got it working with no hacks. The trick is to use a tsconfig.json file and disable automatic definition inclusion. In my original question, I mentioned that I tried this and found I couldn't use compile-on-save. However, that was because I was trying to use the "watch" option, when I really should have been using the "compileOnSave" option.

Here's my complete set of working steps to transform my original, broken project into one that works properly and will continue to work properly on an unmodified install of Visual Studio 2017.

Add a tsconfig.json file to your project at the root.

Configure your file with at least:

{ "compilerOptions": { "types": [] } }

but perhaps with other options as you like. My file looks like this:

{  "compileOnSave": true,  "compilerOptions": {    "types": [],    "sourceMap": true,    "target": "es5",    "noEmitOnError": true  }}

You can learn about other compiler options here:https://www.typescriptlang.org/docs/handbook/compiler-options.html

It's the "types":[] part that prevents the automatic inclusion of definitions.

That means it's up to you to bring in definitions for whatever libraries you use. Fortunately, it's super easy via NuGet. For example, for jQuery, just search for jquery.TypeScript.DefinitelyTyped and install the appropriate version. This will create folders under Scripts/typings.

If you were previously having errors, you might need to clear out some cruft. Clean your project, delete the obj directory at the top of your project's directory structure, and it should now build correctly. I had a couple stray errors that went away when I typed something in the file and then saved again. A restart of Visual Studio might be in order too.

Good luck!


UPDATE: I discovered that when I publish to Azure, I got errors again. However, when I added the directives suggested by Perfa below to my tsconfig.json file, deleted my bin and obj directories and restarted Visual Studio, those errors no longer appeared either. I've now built and rebuilt and published to Azure several times and they seem well and truly gone.

For clarity, my complete tsconfig.json file now looks like this:

{  "compileOnSave": true,  "compilerOptions": {    "types": [],    "sourceMap": true,    "target": "es5",    "noEmitOnError": true  },  "exclude": [    "node_modules",    "obj",    "bin"  ]}


after installing VS 2017 I got this error. To get rid of it I updated my tsconfig.json exclude section with obj, and bin.

"exclude": [    "node_modules",    "obj",    "bin"  ]


I had this exact problem in an old app that I updated to VS 2017, and fixed it by following harley.333's answer -Modifying the Install to include TypeScript 2.0 SDK.

I don't have the rep to comment, but to find it, you have to flip the tab to "Individual Components", then it is on the last grouping, "SDKs, libraries and frameworks."

Install Typescript SDK Screenshot