From 80734f0015a3dfe529cc05efaee4ead50692e025 Mon Sep 17 00:00:00 2001 From: oBusk Date: Wed, 16 Jan 2019 11:37:56 +0100 Subject: [PATCH] Add types for load-google-maps-api --- types/load-google-maps-api/index.d.ts | 59 +++++++++++++++++++ .../load-google-maps-api-tests.ts | 38 ++++++++++++ types/load-google-maps-api/tsconfig.json | 24 ++++++++ types/load-google-maps-api/tslint.json | 1 + 4 files changed, 122 insertions(+) create mode 100644 types/load-google-maps-api/index.d.ts create mode 100644 types/load-google-maps-api/load-google-maps-api-tests.ts create mode 100644 types/load-google-maps-api/tsconfig.json create mode 100644 types/load-google-maps-api/tslint.json diff --git a/types/load-google-maps-api/index.d.ts b/types/load-google-maps-api/index.d.ts new file mode 100644 index 0000000000..818957ff5f --- /dev/null +++ b/types/load-google-maps-api/index.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; + +export = loadGoogleMapsApi; diff --git a/types/load-google-maps-api/load-google-maps-api-tests.ts b/types/load-google-maps-api/load-google-maps-api-tests.ts new file mode 100644 index 0000000000..0d2495de64 --- /dev/null +++ b/types/load-google-maps-api/load-google-maps-api-tests.ts @@ -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 +}); diff --git a/types/load-google-maps-api/tsconfig.json b/types/load-google-maps-api/tsconfig.json new file mode 100644 index 0000000000..7d3af9db08 --- /dev/null +++ b/types/load-google-maps-api/tsconfig.json @@ -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" + ] +} diff --git a/types/load-google-maps-api/tslint.json b/types/load-google-maps-api/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/load-google-maps-api/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }