mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add type definition for non npm-package amap-js-api-station-search (#37106)
This commit is contained in:
parent
5b25a9a40c
commit
e7080fe860
@ -0,0 +1,93 @@
|
||||
// $ExpectType StationSearch
|
||||
new AMap.StationSearch();
|
||||
// $ExpectType StationSearch
|
||||
new AMap.StationSearch({});
|
||||
// $ExpectType StationSearch
|
||||
const stationSearch = new AMap.StationSearch({
|
||||
pageIndex: 1,
|
||||
pageSize: 10,
|
||||
city: '深圳'
|
||||
});
|
||||
|
||||
stationSearch.search('keyword', (status, result) => {
|
||||
const temp: 'error' | 'complete' | 'no_data' = status;
|
||||
status;
|
||||
if (typeof result !== 'string') {
|
||||
// $ExpectType string
|
||||
result.info;
|
||||
// $ExpectType StationInfo[]
|
||||
result.stationInfo;
|
||||
// $ExpectType CityInfo[] | undefined
|
||||
result.cityList;
|
||||
// $ExpectType string[] | undefined
|
||||
result.keywordList;
|
||||
|
||||
const station = result.stationInfo[0];
|
||||
// $ExpectType string
|
||||
station.adcode;
|
||||
// $ExpectType Busline[]
|
||||
station.buslines;
|
||||
// $ExpectType string
|
||||
station.citycode;
|
||||
// $ExpectType string
|
||||
station.id;
|
||||
// $ExpectType LngLat
|
||||
station.location;
|
||||
// $ExpectType string
|
||||
station.name;
|
||||
|
||||
const busline = station.buslines[0];
|
||||
// $ExpectType string
|
||||
busline.end_stop;
|
||||
// $ExpectType string
|
||||
busline.id;
|
||||
// $ExpectType LngLat
|
||||
busline.location;
|
||||
// $ExpectType string
|
||||
busline.name;
|
||||
// $ExpectType string
|
||||
busline.start_stop;
|
||||
} else {
|
||||
// $ExpectType string
|
||||
result;
|
||||
}
|
||||
});
|
||||
|
||||
stationSearch.searchById('id', (status, result) => {
|
||||
const temp: 'error' | 'complete' | 'no_data' = status;
|
||||
// $ExpectType string | SearchResult
|
||||
result;
|
||||
});
|
||||
|
||||
// $ExpectType void
|
||||
stationSearch.setPageIndex(10);
|
||||
// $ExpectType void
|
||||
stationSearch.setPageIndex();
|
||||
|
||||
// $ExpectType void
|
||||
stationSearch.setPageSize(10);
|
||||
// $ExpectType void
|
||||
stationSearch.setPageSize();
|
||||
|
||||
// $ExpectType void
|
||||
stationSearch.setCity('city');
|
||||
// $ExpectType void
|
||||
stationSearch.setCity();
|
||||
|
||||
declare const completeEvent: AMap.StationSearch.EventMap['complete'];
|
||||
// $ExpectType "complete"
|
||||
completeEvent.type;
|
||||
// $ExpectType string
|
||||
completeEvent.info;
|
||||
// $ExpectType CityInfo[] | undefined
|
||||
completeEvent.cityList;
|
||||
// $ExpectType string[] | undefined
|
||||
completeEvent.keywordList;
|
||||
// $ExpectType StationInfo[]
|
||||
completeEvent.stationInfo;
|
||||
|
||||
declare const errorEvent: AMap.StationSearch.EventMap['error'];
|
||||
// $ExpectType "error"
|
||||
errorEvent.type;
|
||||
// $ExpectType string
|
||||
errorEvent.info;
|
||||
158
types/amap-js-api-station-search/index.d.ts
vendored
Normal file
158
types/amap-js-api-station-search/index.d.ts
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
// Type definitions for non-npm package amap-js-api-station-search 1.4
|
||||
// Project: https://lbs.amap.com/api/javascript-api/reference/search#m_AMap.StationSearch
|
||||
// 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 StationSearch {
|
||||
interface EventMap {
|
||||
complete: Event<'complete', SearchResult>;
|
||||
error: Event<'error', { info: string }>;
|
||||
}
|
||||
interface Options {
|
||||
/**
|
||||
* 页码
|
||||
* 默认值:1, 取值范围:1-100
|
||||
*/
|
||||
pageIndex?: number;
|
||||
/**
|
||||
* 单页显示结果条数
|
||||
* 默认值:20, 取值范围:1-100
|
||||
*/
|
||||
pageSize?: number;
|
||||
/**
|
||||
* 公交站点所在城市
|
||||
* 可选值:cityname(中文或中文全拼)、citycode、adcode
|
||||
* 默认值:“全国”
|
||||
*/
|
||||
city?: string;
|
||||
}
|
||||
interface Busline {
|
||||
/**
|
||||
* 公交线路id,该id是唯一标识
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 公交线路名称
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 公交线路途经此站的经纬度
|
||||
*/
|
||||
location: LngLat;
|
||||
/**
|
||||
* 首发站名称
|
||||
*/
|
||||
start_stop: string;
|
||||
/**
|
||||
* 首发站名称
|
||||
*/
|
||||
end_stop: string;
|
||||
}
|
||||
interface StationInfo {
|
||||
/**
|
||||
* 公交站点id,该id是唯一标识
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* 公交站点名称
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 公交站点经纬度
|
||||
*/
|
||||
location: LngLat;
|
||||
/**
|
||||
* 区域编码
|
||||
*/
|
||||
adcode: string;
|
||||
/**
|
||||
* 城市编码
|
||||
*/
|
||||
citycode: string;
|
||||
/**
|
||||
* 途经此站点的公交路线列表
|
||||
*/
|
||||
buslines: Busline[];
|
||||
}
|
||||
interface CityInfo {
|
||||
/**
|
||||
* 城市名称
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 城市编码
|
||||
*/
|
||||
citycode: string;
|
||||
/**
|
||||
* 行政区编码
|
||||
*/
|
||||
adcode: string;
|
||||
/**
|
||||
* 该城市的建议结果数目
|
||||
*/
|
||||
count: number;
|
||||
}
|
||||
interface SearchResult {
|
||||
/**
|
||||
* 成功状态文字描述
|
||||
*/
|
||||
info: string;
|
||||
/**
|
||||
* 根据查询条件返回公交站点信息
|
||||
*/
|
||||
stationInfo: StationInfo[];
|
||||
/**
|
||||
* 查无此公交站时,返回的建议关键字列表,可根据建议关键字查询
|
||||
*/
|
||||
keywordList?: string[];
|
||||
/**
|
||||
* 查该城市无此公交站时,返回的建议城市列表
|
||||
*/
|
||||
cityList?: CityInfo[];
|
||||
}
|
||||
type SearchStatus = 'complete' | 'error' | 'no_data';
|
||||
}
|
||||
/**
|
||||
* 公交站点查询服务
|
||||
*/
|
||||
class StationSearch extends EventEmitter {
|
||||
constructor(options?: StationSearch.Options);
|
||||
/**
|
||||
* 根据给定的公交站点id进行公交站点详情检索
|
||||
* @param id 公交站点的唯一标识
|
||||
* @param callback 查询回调
|
||||
*/
|
||||
searchById(
|
||||
id: string,
|
||||
callback: (status: StationSearch.SearchStatus, result: StationSearch.SearchResult | string) => void
|
||||
): void;
|
||||
/**
|
||||
* 根据给定公交站点名称进行公交站点详情查询
|
||||
* @param keyword 查询关键词,多个关键字用"|"分割
|
||||
* @param callback 查询回调
|
||||
*/
|
||||
search(
|
||||
keyword: string,
|
||||
callback: (status: StationSearch.SearchStatus, result: StationSearch.SearchResult | string) => void
|
||||
): void;
|
||||
/**
|
||||
* 设置查询结果页码
|
||||
* @param pageIndex 页码,取值范围:1-100
|
||||
*/
|
||||
setPageIndex(pageIndex?: number): void;
|
||||
/**
|
||||
* 设置单页显示结果条数
|
||||
* @param pageSize 条数,取值范围:1-100
|
||||
*/
|
||||
setPageSize(pageSize?: number): void;
|
||||
/**
|
||||
* 设置查询城市
|
||||
* @param city 城市:cityname(中文或中文全拼)、citycode或adcode
|
||||
*/
|
||||
setCity(city?: string): void;
|
||||
}
|
||||
}
|
||||
24
types/amap-js-api-station-search/tsconfig.json
Normal file
24
types/amap-js-api-station-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-station-search-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/amap-js-api-station-search/tslint.json
Normal file
3
types/amap-js-api-station-search/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user