From bfab99e84dbebeee5f039e357b945e0c05c18739 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Thu, 3 Oct 2019 02:54:27 +0800 Subject: [PATCH] New definition for non npm package amap-js-api-map-type (#38759) --- .../amap-js-api-map-type-tests.ts | 32 ++++++++++++++++ types/amap-js-api-map-type/index.d.ts | 38 +++++++++++++++++++ types/amap-js-api-map-type/tsconfig.json | 24 ++++++++++++ types/amap-js-api-map-type/tslint.json | 3 ++ 4 files changed, 97 insertions(+) create mode 100644 types/amap-js-api-map-type/amap-js-api-map-type-tests.ts create mode 100644 types/amap-js-api-map-type/index.d.ts create mode 100644 types/amap-js-api-map-type/tsconfig.json create mode 100644 types/amap-js-api-map-type/tslint.json diff --git a/types/amap-js-api-map-type/amap-js-api-map-type-tests.ts b/types/amap-js-api-map-type/amap-js-api-map-type-tests.ts new file mode 100644 index 0000000000..49e276cd99 --- /dev/null +++ b/types/amap-js-api-map-type/amap-js-api-map-type-tests.ts @@ -0,0 +1,32 @@ +declare const map: AMap.Map; + +// $ExpectType MapType +new AMap.MapType(); +// $ExpectType MapType +new AMap.MapType({}); +// $ExpectType MapType +const mapType = new AMap.MapType({ + defaultType: 1, + showTraffic: true, + showRoad: true +}); + +// $ExpectError +new AMap.MapType({ + defaultType: 2 +}); + +// $ExpectType void +mapType.show(); + +// $ExpectType void +mapType.hide(); + +mapType.on('show', (event: AMap.MapType.EventMap['show']) => { + // $ExpectType "show" + event.type; +}); +mapType.on('hide', (event: AMap.MapType.EventMap['hide']) => { + // $ExpectType "hide" + event.type; +}); diff --git a/types/amap-js-api-map-type/index.d.ts b/types/amap-js-api-map-type/index.d.ts new file mode 100644 index 0000000000..e8f92ab9be --- /dev/null +++ b/types/amap-js-api-map-type/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for non-npm package amap-js-api-map-type 1.4 +// Project: https://lbs.amap.com/api/javascript-api/reference/map-control#AMap.MapType +// Definitions by: breeze9527 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/// + +declare namespace AMap { + namespace MapType { + interface EventMap { + hide: Event<'hide'>; + show: Event<'show'>; + } + interface Options { + /** + * 初始化默认图层类型,默认为0 + * 取值为0:默认底图 + * 取值为1:卫星图 + */ + defaultType?: 0 | 1; + /** + * 是否叠加实时交通图层,默认false + */ + showTraffic?: boolean; + /** + * 是否叠加路网图层,默认false + */ + showRoad?: boolean; + } + } + + class MapType extends EventEmitter { + constructor(options?: MapType.Options); + show(): void; + hide(): void; + } +} diff --git a/types/amap-js-api-map-type/tsconfig.json b/types/amap-js-api-map-type/tsconfig.json new file mode 100644 index 0000000000..018ac18b52 --- /dev/null +++ b/types/amap-js-api-map-type/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noEmit": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "amap-js-api-map-type-tests.ts" + ] +} diff --git a/types/amap-js-api-map-type/tslint.json b/types/amap-js-api-map-type/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/amap-js-api-map-type/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}