Please see the edit below
I have used the following package as a base for my VS Project -> https://github.com/AngularClass/angular2-webpack-starter
Everything worked nicely in Visual Studio code, I then tried to convert it to a Visual Studio 2017 Project (node.js web)
Now some problems appeared
VS seems to install TypeScript definitions into a special folder C:\Users\MyUser\AppData\Local\Microsoft\TypeScript\node_modules\@types
Additionally I included @types/node in my package.json which resulted in the appropriate node_modules folder.
now VS complains with error code TS4090 (Conflicting defintions for 'node').
Is there a possibility apart from deleting the folder in \AppData to tell VS which @types it should use?
The whole integration of TypeScript isn't really clear to me... Does MSBuild recognize an existing tsconfig.json? or would I have to configure it in in the project-file as seen here?
EDIT
I just noticed that I was actually editing a .js file. As soon as I changed the extension to .ts every warning and error vanished. I also got many typescript errors (like TS2307, can't find module '@angular/core') before changing the extension from .js to .ts
The file just did an import (from node)
import * as fs from 'fs';
Could anyone explain why I got this errors? Why a JS files causes 200+ typescript errors (some don't even seem related to the import from above)?
EDIT2 the errors which occur are
- TS2403 - Subsequent Variable declarations must have the same type.
- TS2300 - Duplicate identifier 'PropertyKey'
- TS4090 - Conflicting definitions for 'node' found (paraphrasing: found in
./node_modules
andC:\Users\MyUser\AppData\Local\Microsoft\TypeScript\node_modules\@types
All the errors are caused by d.ts
files in C:\Users\MyUser\AppData\Local\Microsoft\TypeScript\node_modules\@types
or C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TypeScript\lib.es6.d.ts
like Bowden Kelly noted, this seems the cause for this problems seems to be the definition files MS put in here C:\Users\MyUser\AppData\Local\Microsoft\TypeScript\node_modules\@types
, as soon as I install my own definition files in ./node_modules
VS finds both definitions (if present) when editing JS files.
So the solution would either be:
- doing it the MS Way
- somehow exclude MS Directory