'How do I prevent (uninstall) TypeScript installing and referencing it's own @types into AppData\Local
I'm running into a bit of a confusing issue where it seems that TypeScript is installing its own copy of React into it's own global cache (not sure what its called? assuming thats what it is) and referencing it in my project.
Specifically I end up with two references to React one that is located in the root of my project
C:\MyProject\node_modules\@types\react
and then another reference in
C:\Users\MyUserName\AppData\Local\Microsoft\TypeScript\3.0\node_modules\@types\react
How do I control and uninstall references that end up in the TypeScript local folder? What might I be doing in my project that could be causing this secondary reference?
Here is what my tsconfig.json file looks like:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"sourceMap": true,
"jsx": "react",
"lib": [ "es6", "dom" ],
"removeComments": true,
"typeRoots": [
"/Types/"
]
},
"compileOnSave": false,
"exclude": [
"/node_modules/",
"/bin",
"/obj"
]
}
Solution 1:[1]
The feature that is downloading the type declarations to C:\Users\MyUserName\AppData\Local\Microsoft\TypeScript\3.0\node_modules is called "Automatic Type Acquisition" and is intended for JavaScript projects. Since your project has a tsconfig.json file, Automatic Type Acquisition should be inactive and any previously downloaded files should not be used; if you have evidence that they are being used and are causing problems with your project, please update the question. Assuming you are using Visual Studio Code, you can disable Automatic Type Acquisition by setting the typescript.disableAutomaticTypeAcquisition setting to true.
Solution 2:[2]
These issues comes up depending on your IDE and is resolved in different ways
For Visual Studio 2019:
Go to Options-> Text Editor -> JavaScript/TypeScript-> Project and Uncheck TypeAcquisition for Javascript

Close VisualStudio
Delete the Folder under C:\Users\ [Username]\AppData\Local\Microsoft\TypeScript\ [VersionOfConcern]
Reload Solution and your errors should be gone
VS Code Users should be refer to the tsconfig.json file option:
{
[...],
"typeAcquisition": {"enable": false}
}
I did not test the Solution for VS Code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt McCutchen |
| Solution 2 | Dominik Sand |
