One way to prevent this from happening is to modify your tsconfig.json file to limit the set of types that are automatically imported into your project.
I had this same problem, and I fixed it by adding:
types: []
into my tsconfig.json file. What this does is disable's TypeScript (and by extension VSCode) from automatically importing all node packages that being with @types/
into the project configuration. This doesn't prevent TS from importing those type definitions if you explicitly import a package using those types.
In my specific case, the console
definition was coming from @types/node
, which had been imported into the project as a dependency of Storybook. However, my project was a webpack project, intended to run in a browser, so importing Node.js types into my source code made no sense. The base set of types that you would want to use in a browser are dom types, not node types.
Depending on your project, you may have to explicitly add the set of base type packages into the types parameter (types: ["dom", "react"]
and so on). However, in my case this turned out to be unnecessary, my project was able to compile just fine with an empty list. And the tendency of VSCode to automatically import 'console' appears to have completely gone away; I haven't noticed any other ill effects so far.
More information on setting types in tsconfig.json here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html