Add definition for non npm package: amap-js-api-district-search (#34856)

* [amap-js-api] update to v1.4.14

* Add definition for non npm package: amap-js-api-district-search
This commit is contained in:
breeze9527 2019-04-20 03:58:51 +08:00 committed by Armando Aguirre
parent 114e16d6bb
commit bed07e18ca
4 changed files with 206 additions and 0 deletions

View File

@ -0,0 +1,71 @@
// $ExpectType DistrictSearch
new AMap.DistrictSearch();
// $ExpectType DistrictSearch
new AMap.DistrictSearch({});
// $ExpectType DistrictSearch
const districtSearch = new AMap.DistrictSearch({
level: 'city',
showbiz: true,
extensions: 'all',
subdistrict: 1
});
// $ExpectType void
districtSearch.search('keyword', (status, result) => {
const temp: 'error' | 'complete' | 'no_data' = status;
// $ExpectType string | SearchResult
result;
if (typeof result !== 'string') {
// $ExpectType string
result.info;
// $ExpectType District[]
result.districtList;
{
const district = result.districtList[0];
// $ExpectType string
district.adcode;
// $ExpectType LngLat[][] | undefined
district.boundaries;
// $ExpectType LngLat
district.center;
// $ExpectType string
district.citycode;
// $ExpectType District[] | undefined
district.districtList;
// $ExpectType Level
district.level;
// $ExpectType string
district.name;
}
} else {
// $ExpectType string
result;
}
});
declare const level: 'country' | 'province' | 'city' | 'district' | 'biz_area';
// $ExpectType void
districtSearch.setLevel(level);
districtSearch.setLevel();
// $ExpectType void
districtSearch.setSubdistrict(3);
// $ExpectError
districtSearch.setSubdistrict(4);
districtSearch.on('complete', (event: AMap.DistrictSearch.EventMap['complete']) => {
// $ExpectType "complete"
event.type;
// $ExpectType string
event.info;
// $ExpectType District[]
event.districtList;
});
districtSearch.on('error', (event: AMap.DistrictSearch.EventMap['error']) => {
// $ExpectType "error"
event.type;
// $ExpectType string
event.info;
});

View File

@ -0,0 +1,108 @@
// Type definitions for non-npm package amap-js-api-district-search 1.4
// Project: https://lbs.amap.com/api/javascript-api/reference/search#m_AMap.DistrictSearch
// Definitions by: breeze9527 <https://github.com/breeze9527>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/// <reference types="amap-js-api" />
declare namespace AMap {
namespace DistrictSearch {
interface EventMap {
error: Event<'error', { info: string; }>;
complete: Event<'complete', SearchResult>;
}
type Level = 'country' | 'province' | 'city' | 'district' | 'biz_area';
interface Options {
/**
*
*/
level?: Level;
/**
*
*/
showbiz?: boolean;
/**
*
*/
extensions?: 'base' | 'all';
/**
*
* 0
* 1
* 2
* 3
*/
subdistrict?: 0 | 1 | 2 | 3;
}
interface District {
/**
*
*/
name: string;
/**
*
*/
center: LngLat;
/**
*
*/
citycode: string;
/**
*
*/
adcode: string;
/**
*
*/
level: Level;
/**
*
*/
boundaries?: LngLat[][];
/**
*
*/
districtList?: District[];
}
interface SearchResult {
/**
*
*/
info: string;
/**
*
*/
districtList: District[];
}
type SearchStatus = 'complete' | 'error' | 'no_data';
}
class DistrictSearch extends EventEmitter {
/**
*
* @param options
*/
constructor(options?: DistrictSearch.Options);
/**
*
* @param keyword
* @param callback
*/
search(
keyword: string,
callback: (status: DistrictSearch.SearchStatus, result: DistrictSearch.SearchResult | string) => void
): void;
/**
*
* @param level
*/
setLevel(level?: DistrictSearch.Level): void;
/**
*
* @param district
*/
setSubdistrict(district?: 0 | 1 | 2 | 3): void;
// internal
setExtensions(extensions?: boolean): void;
}
}

View File

@ -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-district-search-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}