Add defition of non npm package amap-js-api-city-search

This commit is contained in:
breeze9527 2019-04-13 19:16:54 +08:00
parent d8748201c7
commit 19fcce5bfe
4 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,63 @@
// $ExpectType CitySearch
const citySearch = new AMap.CitySearch();
citySearch.getLocalCity((status, result) => {
const statusTemp: 'error' | 'complete' | 'no_data' = status;
if (typeof result !== 'string') {
// $ExpectType SearchResult
result;
// $ExpectType string
result.adcode;
// $ExpectType Bounds
result.bounds;
// $ExpectType string
result.city;
// $ExpectType string
result.info;
// $ExpectType string
result.infocode;
// $ExpectType string
result.province;
// $ExpectType string
result.rectangle;
// $ExpectType string
result.status;
} else {
// $ExpectType string
result;
}
});
// $ExpectType void
citySearch.getCityByIp('ip', (status, result) => {
const statusTemp: 'error' | 'complete' | 'no_data' = status;
const resultTemp: AMap.CitySearch.SearchResult | string = result;
});
citySearch.on('complete', (event: AMap.CitySearch.EventMap['complete']) => {
// $ExpectType "complete"
event.type;
// $ExpectType string
event.adcode;
// $ExpectType Bounds
event.bounds;
// $ExpectType string
event.city;
// $ExpectType string
event.info;
// $ExpectType string
event.infocode;
// $ExpectType string
event.province;
// $ExpectType string
event.rectangle;
// $ExpectType string
event.status;
});
citySearch.on('error', (event: AMap.CitySearch.EventMap['error']) => {
// $ExpectType string
event.info;
// $ExpectType "error"
event.type;
});

View File

@ -0,0 +1,67 @@
// Type definitions for non-npm package amap-js-api-city-search 1.4
// Project: https://lbs.amap.com/api/javascript-api/reference/location#m_AMap.CitySearch
// 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 CitySearch {
interface EventMap {
complete: Event<'complete', SearchResult>;
error: Event<'error', { info: string }>;
}
interface SearchResult {
/**
*
*/
city: string;
rectangle: string;
/**
*
*/
bounds: Bounds;
/**
*
*/
info: string;
/**
*
*/
adcode: string;
/**
*
*/
infocode: string;
/**
*
*/
province: string;
/**
*
*/
status: string;
}
type SearchStatus = 'error' | 'complete' | 'no_data';
}
/**
* IP返回对应城市信息
*/
class CitySearch extends EventEmitter {
/**
* IP
* @param callback
*/
getLocalCity(callback: (status: CitySearch.SearchStatus, result: CitySearch.SearchResult | string) => void): void;
/**
* IP地址返回对应城市信息
* @param ip IP
* @param callback
*/
getCityByIp(
ip: string,
callback: (status: CitySearch.SearchStatus, result: CitySearch.SearchResult | string) => void
): 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-city-search-tests.ts"
]
}

View File

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