How to install Typescript typings for google maps

前端 未结 12 1097
春和景丽
春和景丽 2020-11-28 04:07

How can it be done - I\'ve tried combinations of

typings install [googlemaps | google.maps] [--ambient] --save

and end up with variations o

12条回答
  •  隐瞒了意图╮
    2020-11-28 04:25

    I struggled to define the google object on the window, finally found a good way, by extending Window interface.

    Just create a google-maps.d.ts file with this:

    import '@types/googlemaps';
    
    declare global {
      interface Window {
        google: typeof google;
      }
    }
    

    And add it to a directory called types at your root folder. Then point to this folder in your tsconfig.json file.

    // tsconfig.json
    compilerOptions: {
       ...
       "typeRoots": [
         "node_modules/@types",
         "types"
       ],
       ...
    }
    

提交回复
热议问题