typescript谷歌地图错误



我正在用Udemy课程学习打字脚本。我做了一个使用谷歌地图的练习。

然后,当我使用nvm时,我将节点版本更新为16。当我更新节点时,我执行了将typescript安装到新版本的命令

$ npm install -g typescript ts-node
$ npm install -g @types/node @types/google.maps

我开始了一个新的练习,我只需要写一个控制台日志

index.ts

console.log('Hi there')

然后我应该编译文件

$ ts index.ts

生成了index.js,但我也收到了错误提示音

...
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:51:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'path' must be of type '(LatLngLiteral | LatLng)[] | MVCArray<any>', but here has type 'LatLng[] | MVCArray<LatLng> | LatLngLiteral[]'.
51         path?: MVCArray<LatLng> | LatLng[] | LatLngLiteral[];
           ~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5066:5
    5066     path?: google.maps.MVCArray<any>|null|
             ~~~~
    'path' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:75:11 - error TS2300: Duplicate identifier 'Polygon'.
75     class Polygon extends MVCObject {
             ~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:4804:9
    4804   class Polygon extends google.maps.MVCObject {
                 ~~~~~~~
    'Polygon' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:145:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'paths' must be of type 'any[] | MVCArray<any>', but here has type 'LatLng[] | MVCArray<LatLng> | LatLngLiteral[] | MVCArray<MVCArray<LatLng>> | LatLng[][] | LatLngLiteral[][]'.
145         paths?:
            ~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:4932:5
    4932     paths?: google.maps.MVCArray<any>|null|any[];
             ~~~~~
    'paths' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:194:11 - error TS2300: Duplicate identifier 'Rectangle'.
194     class Rectangle extends MVCObject {
              ~~~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5122:9
    5122   class Rectangle extends google.maps.MVCObject {
                 ~~~~~~~~~
    'Rectangle' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:226:11 - error TS2300: Duplicate identifier 'Circle'.
226     class Circle extends MVCObject {
              ~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:74:9
    74   class Circle extends google.maps.MVCObject {
               ~~~~~~
    'Circle' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:322:9 - error TS2300: Duplicate identifier 'CENTER'.
322         CENTER = 0,
            ~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5883:5
    5883     CENTER = 0.0,
             ~~~~~~
    'CENTER' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:324:9 - error TS2300: Duplicate identifier 'INSIDE'.
324         INSIDE = 1,
            ~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5887:5
    5887     INSIDE = 1.0,
             ~~~~~~
    'INSIDE' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/polygon.d.ts:326:9 - error TS2300: Duplicate identifier 'OUTSIDE'.
326         OUTSIDE = 2,
            ~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5891:5
    5891     OUTSIDE = 2.0,
             ~~~~~~~
    'OUTSIDE' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: StreetViewService, OK, UNKNOWN_ERROR, ZERO_RESULTS, BEST, NEAREST, DEFAULT, OUTDOOR
1 declare namespace google.maps {
  ~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:20:1
    20 declare namespace google.maps {
       ~~~~~~~
    Conflicts are in this file.
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:25:9 - error TS2687: All declarations of 'location' must have identical modifiers.
25         location: LatLng | LatLngLiteral;
           ~~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:32:9 - error TS2687: All declarations of 'pano' must have identical modifiers.
32         pano: string;
           ~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:38:9 - error TS2687: All declarations of 'pano' must have identical modifiers.
38         pano?: string;
           ~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:57:9 - error TS2687: All declarations of 'tiles' must have identical modifiers.
57         tiles?: StreetViewTileData;
           ~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:61:9 - error TS2687: All declarations of 'description' must have identical modifiers.
61         description?: string;
           ~~~~~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:62:9 - error TS2687: All declarations of 'heading' must have identical modifiers.
62         heading?: number;
           ~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view-service.d.ts:63:9 - error TS2687: All declarations of 'pano' must have identical modifiers.
63         pano?: string;
           ~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:2:11 - error TS2300: Duplicate identifier 'StreetViewPanorama'.
2     class StreetViewPanorama extends MVCObject {
            ~~~~~~~~~~~~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5452:9
    5452   class StreetViewPanorama extends google.maps.MVCObject {
                 ~~~~~~~~~~~~~~~~~~
    'StreetViewPanorama' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:69:9 - error TS2687: All declarations of 'centerHeading' must have identical modifiers.
69         centerHeading?: number;
           ~~~~~~~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:70:9 - error TS2687: All declarations of 'tileSize' must have identical modifiers.
70         tileSize?: Size;
           ~~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:71:9 - error TS2687: All declarations of 'worldSize' must have identical modifiers.
71         worldSize?: Size;
           ~~~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:75:9 - error TS2687: All declarations of 'heading' must have identical modifiers.
75         heading?: number;
           ~~~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:76:9 - error TS2687: All declarations of 'pitch' must have identical modifiers.
76         pitch?: number;
           ~~~~~
../../../../../../node_modules/@types/googlemaps/reference/street-view.d.ts:79:11 - error TS2300: Duplicate identifier 'StreetViewCoverageLayer'.
79     class StreetViewCoverageLayer extends MVCObject {
             ~~~~~~~~~~~~~~~~~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:5347:9
    5347   class StreetViewCoverageLayer extends google.maps.MVCObject {
                 ~~~~~~~~~~~~~~~~~~~~~~~
    'StreetViewCoverageLayer' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/visualization.d.ts:2:11 - error TS2300: Duplicate identifier 'HeatmapLayer'.
2     class HeatmapLayer extends MVCObject {
            ~~~~~~~~~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:8717:9
    8717   class HeatmapLayer extends google.maps.MVCObject {
                 ~~~~~~~~~~~~
    'HeatmapLayer' was also declared here.
../../../../../../node_modules/@types/googlemaps/reference/visualization.d.ts:12:9 - error TS2687: All declarations of 'data' must have identical modifiers.
12         data: MVCArray<LatLng | WeightedLocation> | Array<LatLng | WeightedLocation>;
           ~~~~
../../../../../../node_modules/@types/googlemaps/reference/visualization.d.ts:12:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'data' must be of type 'MVCArray<any> | (LatLng | WeightedLocation)[]', but here has type '(LatLng | WeightedLocation)[] | MVCArray<LatLng | WeightedLocation>'.
12         data: MVCArray<LatLng | WeightedLocation> | Array<LatLng | WeightedLocation>;
           ~~~~
  ../../../../../../node_modules/@types/google.maps/index.d.ts:8752:5
    8752     data?: google.maps.MVCArray<any>|null|
             ~~~~
    'data' was also declared here.

Found 240 errors.

我一直在尝试修复这个卸载typescript并重新安装的问题,但我做不到。

此外,我不确定为什么我会得到谷歌地图错误,因为谷歌地图没有在我编译的文件中使用

@types/google.maps与不推荐使用的包@types/googlemaps 冲突

尝试

npm uninstall @types/googlemaps

最新更新