mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
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:
parent
114e16d6bb
commit
bed07e18ca
@ -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;
|
||||
});
|
||||
108
types/amap-js-api-district-search/index.d.ts
vendored
Normal file
108
types/amap-js-api-district-search/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
24
types/amap-js-api-district-search/tsconfig.json
Normal file
24
types/amap-js-api-district-search/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/amap-js-api-district-search/tslint.json
Normal file
3
types/amap-js-api-district-search/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user