Visual Studio doesn't recognize imported npm package?

When importing npm packages into my project in Visual Studio, it always seems to me that packages are sometimes not recognized no matter how many times I update folders.

enter image description here

The folder is react-google-mapsdefinitely located in my node_modules folder. However, for some reason, Visual Studio does not see this error and emphasizes it as an error. And because of this, all relevant intellisense also do not appear. Oddly enough, he really can recognize react!

What should I do so that Visual Studio recognizes new packages that I just installed via npm in the console so that I can import them without highlighted errors?

+4
source share
1 answer

I believe the problem is what react-google-mapsis the JavaScript module. To import a TypeScript module, you need some characters that translate JavaScript into TypeScript, for example. from the DefinitelyTyped repository.

A quick search did not find such typifications, why I assume that you have not set any types for this.

There are two solutions, if so.

  • Write sample data and pass it on to a specific type or type registry. This is my recommended approach. Do something back to the community by writing typing and publishing it to others.
  • Declare a module in your project to disable import. This one does not give you any IntelliSence, therefore it only blocks import.

, react-google-maps.d.ts :

declare module "react-google-maps" {
    export var GoogleMap;
    export var Marker;
}
0

Source: https://habr.com/ru/post/1652421/


All Articles