ERROR in node_modules/@types/googlemaps/index.d.ts — A tuple type element list cannot be empty

自作多情 提交于 2020-08-27 06:39:28

问题


while trying to integrate the angular google maps - agm librarie in my angular project i got this error :

somthing is worng with some configuration or maybe something i have missed i m working with material 6 and angular 6 in this project thanks for your help

in terminal console

ERROR in node_modules/@types/googlemaps/index.d.ts(63,25): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(72,25): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(94,15): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(100,18): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(106,20): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(115,26): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(121,15): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(130,28): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(155,29): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(167,22): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(176,23): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(185,23): error TS1122: A tuple type element list cannot be empty.
node_modules/@types/googlemaps/index.d.ts(3308,76): error TS2370: A rest parameter must be of an array type.

here is what i did :

npm i @agm/core 
npm i -D @types/googlemaps 
ng add @angular-material-extensions/google-maps-autocomplete

app.module.ts

import { AgmCoreModule } from '@agm/core';
import { MatGoogleMapsAutocompleteModule } from '@angular-material-extensions/google-maps-autocomplete';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [
     AgmCoreModule.forRoot({
          apiKey: 'YOUR_KEY',
          libraries: ['places']
        }),
     MatGoogleMapsAutocompleteModule.forRoot(), ...],  
  bootstrap: [AppComponent]
})
export class AppModule {
}

mycomponent.component.html

<mat-form-field>
  <mat-label>Address << using the directive >></mat-label>
  <input matInput
       matGoogleMapsAutocomplete
       [country]="de"
       (onAutocompleteSelected)="onAutocompleteSelected($event)"
       (onLocationSelected)="onLocationSelected($event)">
</mat-form-field>

mycomponent.component.ts

...
import {} from 'googlemaps';



@Component({
  selector : ...
...

src/index.d.ts

declare module 'googlemaps';

tsconfig.app.json

    ...
   "types": [
      "googlemaps"
    ]
   ...

package.json

 "dependencies": {
    "@agm/core": "^1.1.0",
    "@angular-material-extensions/google-maps-autocomplete": "^2.0.0",
    "@angular/animations": "^6.1.10",
    "@angular/cdk": "^6.1.0",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/material": "^6.1.0",
    "@angular/material-moment-adapter": "^8.2.3",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "googleapis": "28.1.0",
    ...
    "@types/googlemaps": "^3.39.0",
    "rxjs": "^6.5.3",
    "rxjs-compat": "^6.5.3",
    "zone.js": "~0.8.26"
  },

followed tutorial : link to tuto used

Solution : i don't know why and how but rolling back to an older version worked for me !! but that's not the proper solution i looking for


回答1:


You need to go back to a version that works.

In your package.json file, choose an older version specifically:

...    
"@types/googlemaps" :  "3.26.15"
...



回答2:


I am getting the same error as defined above. but when I go to file in nodemodules/@types/GoogleMaps and open file index.d.ts. I see lot of functions there as shown in fig. for example we have a function bounds_changed: []; when I changed this function to bounds_changed:[''] it is working fine but we need an exact solution how to fix this because we are installing node modules every time when we create a build.

interface MapHandlerMap { /** * This event is fired when the viewport bounds have changed. * @see {@link https://developers.google.com/maps/documentation/javascript/reference/map#Map.bounds_changed Maps JavaScript API} * @see {@link Map#getBounds} * @see {@link Map#fitBounds} * @see {@link Map#panToBounds} */ bounds_changed: [];

    /**
     * This event is fired when the map center property changes.
     * @see {@link https://developers.google.com/maps/documentation/javascript/reference/map#Map.center_changed Maps JavaScript API}
     * @see {@link MapOptions#center}
     * @see {@link Map#getCenter}
     * @see {@link Map#setCenter}
     */
    center_changed: [];



回答3:


downgrade your version of googlemapps https://www.npmjs.com/package/@types/googlemaps/v/3.38.0

run the command npm i @types/googlemaps@3.38.0




回答4:


If you will git checkout this commit

b9cfc7f2cdf78a7f4b91a753d10865a2

you will see how they wrote this tutorial with your version of angular

https://github.com/angular-material-extensions/google-maps-autocomplete/commit/ba8c7c1a3fb717e8033a343aa27bc48fe7302f97#diff-b9cfc7f2cdf78a7f4b91a753d10865a2

you can go to this page to find other angular versions if you will need in the future https://github.com/angular-material-extensions/google-maps-autocomplete/commits/master?after=02ef8485d57c520d5c36d657d7402c1ab4aad7c5+34&path%5B%5D=package.json

Hope this was helpful :)



来源:https://stackoverflow.com/questions/59472584/error-in-node-modules-types-googlemaps-index-d-ts-a-tuple-type-element-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!