Add type definition for non npm-package amap-js-api-station-search (#37106)

This commit is contained in:
breeze9527 2019-07-25 04:03:40 +08:00 committed by Wesley Wigham
parent 5b25a9a40c
commit e7080fe860
4 changed files with 278 additions and 0 deletions

View File

@ -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;

View 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;
/**
*
* citynamecitycodeadcode
*
*/
city?: string;
}
interface Busline {
/**
* 线idid是唯一标识
*/
id: string;
/**
* 线
*/
name: string;
/**
* 线
*/
location: LngLat;
/**
*
*/
start_stop: string;
/**
*
*/
end_stop: string;
}
interface StationInfo {
/**
* idid是唯一标识
*/
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 城市:citynamecitycode或adcode
*/
setCity(city?: string): 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-station-search-tests.ts"
]
}

View File

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