Add types for load-google-maps-api

This commit is contained in:
oBusk
2019-01-16 11:37:56 +01:00
parent 5f012ded23
commit 80734f0015
4 changed files with 122 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
// Type definitions for load-google-maps-api 1.3
// Project: https://github.com/yuanqing/load-google-maps-api#readme
// Definitions by: Oscar Busk <https://github.com/oBusk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="googlemaps" />
interface Options {
/**
* Client usage reporting channel
*
* https://developers.google.com/maps/premium/reports/usage-reports#channels
*/
channel?: string;
/**
* Client ID
*
* https://developers.google.com/maps/documentation/javascript/get-api-key#specifying-a-client-id-when-loading-the-api
*/
client?: string;
/**
* Your API key
*
* https://developers.google.com/maps/documentation/javascript/get-api-key#step-2-add-the-api-key-to-your-application
*/
key?: string;
/**
* https://developers.google.com/maps/documentation/javascript/localization#Language
*/
language?: string;
/**
* Supplemental libraries to load
*
* Default Value `[]`
*
* https://developers.google.com/maps/documentation/javascript/libraries
*/
libraries?: string[];
/**
* https://developers.google.com/maps/documentation/javascript/localization#Region
*/
region?: string;
/**
* Time in milliseconds before rejecting the Promise
*
* Default Value `10000`
*/
timeout?: number;
/**
* API Version
*
* https://developers.google.com/maps/documentation/javascript/versions
*/
v?: string;
}
declare function loadGoogleMapsApi(options?: Options): Promise<typeof google.maps>;
export = loadGoogleMapsApi;
@@ -0,0 +1,38 @@
import loadGoogleMapsApi = require('load-google-maps-api');
// Example from README.md https://github.com/yuanqing/load-google-maps-api#usage
loadGoogleMapsApi().then((googleMaps) => {
new googleMaps.Map(document.querySelector('.map'), {
center: {
lat: 40.7484405,
lng: -73.9944191
},
zoom: 12
});
}).catch((error) => {
console.error(error);
});
loadGoogleMapsApi({ libraries: 'drawing' }); // $ExpectError
loadGoogleMapsApi({ v: 3 }); // $ExpectError
loadGoogleMapsApi({ timeout: '1000' }); // $ExpectError
loadGoogleMapsApi({
channel: 'customer',
client: '12345',
key: 'abcde',
language: 'se',
libraries: [
'drawing',
'geometry',
'places',
'visualization',
],
region: 'SE',
timeout: 500,
v: '3.33',
}).then(gm => {
gm; // $ExpectType typeof maps
const map = new gm.Map(document.querySelector('.map')); // $ExpectType Map
const polygon = new gm.Polygon(); // $ExpectType Polygon
});
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"load-google-maps-api-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }