// error Do not use a triple slash reference for xxx, use `import` style instead
// eslint-disable-next-line spaced-comment, @typescript-eslint/triple-slash-reference
///
/**
* 小程序类型申明垫片. 参考官网 https://opendocs.alipay.com/mini/api,
* 依赖mini-types - https://www.npmjs.com/package/mini-types, 可能跟实际api定义未同步, 所以通过垫片修复.
*/
declare namespace my {
/**
* 小程序错误对象,错误对象为纯对象,没有继承原生Error类.
*
* @template C Type of error code, 错误码通常为number类型, 不同的api有不同的错误码.
* @see https://opendocs.alipay.com/mini/00nmrr
*/
interface IError {
/**
* 错误码.
*/
error: C;
/**
* 错误消息.
*/
errorMessage: string;
}
/**
* 小程序环境变量对象.
*
* @see https://opendocs.alipay.com/mini/api/env
*/
interface Env {
/**
* 文件系统中的用户目录路径 (本地路径)。
*/
USER_DATA_PATH: string;
/**
* 客户端名称简写。支付宝客户端为 'ap'.
*/
clientName: string;
/**
* 客户端版本号。例如"10.2.6".
*/
clientVersion: string;
/**
* 设置的语言.
*/
language: string;
/**
* 系统名称.
*/
platform: string;
}
/**
* 小程序环境变量对象.
*/
const env: Env;
// //////////////////////////////////////////////////////////////////////////
// mini-types/types/api/open/auth.d.ts
// //////////////////////////////////////////////////////////////////////////
/**
* 授权码扩展类型.
*/
interface GetAuthCodeOptionsScopeExtended {
/* eslint-disable camelcase */
/**
* 内部使用scope获取用户已领取优惠券, 模拟器中无法模拟, 只能真机中调用.
*/
voucher_query: 'voucher_query';
/* eslint-enable camelcase */
/**
* 皮肤兑换.
*/
facepayskin: 'facepayskin';
}
/**
* 获取授权码扩展选项.
*/
interface IGetAuthCodeOptionsExtended extends Omit {
/**
* 授权类型,默认 auth_base。支持 auth_base(静默授权)/ auth_user(主动授权) / auth_zhima(芝麻信用).
* 扩展`my.GetAuthCodeOptionsScopeExtended`可自定义其它类型.
* 联合`my.GetAuthCodeOptionsScope`类型处理扩展自定义类型后如果传递的类型有自定义类型和内置类型时报类型错误,
* 如果直接使用`my.getAuthCode`作为函数参数或者赋值给变量, 根据函数重载可能会先找到我们扩展的函数,
* 也会导致`my.GetAuthCodeOptionsScope`不能被识别报类型错误.
*/
scopes?: (keyof GetAuthCodeOptionsScopeExtended | my.GetAuthCodeOptionsScope) |
(keyof GetAuthCodeOptionsScopeExtended | my.GetAuthCodeOptionsScope)[];
}
/**
* 获取授权码扩展方法。
* see also https://opendocs.alipay.com/mini/api/openapi-authorize.
*/
function getAuthCode (options: IGetAuthCodeOptionsExtended): void;
// //////////////////////////////////////////////////////////////////////////
// mini-types/types/api/location.d.ts
// //////////////////////////////////////////////////////////////////////////
/**
* 位置垫片.
*
* https://opendocs.alipay.com/mini/api/location#success%20%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0
*/
interface IChooseLocationResult {
/**
* 省份名称.
*/
readonly provinceName: string;
/**
* 城市名称.
*/
readonly cityName: string;
}
// //////////////////////////////////////////////////////////////////////////
// mini-types/types/api/open/ui/map.d.ts
// //////////////////////////////////////////////////////////////////////////
/**
* 地图标记.
*
* @see https://opendocs.alipay.com/mini/component/map#markers
*/
interface IMarker {
id: string | number;
label?: {
content: string;
color?: string;
fontSize?: number;
borderRadius?: string;
bgColor?: string;
padding?: number;
};
iconPath: string;
latitude: number;
longitude: number;
width: number;
height: number;
}
/**
* 地图上下文类型申明垫片, 参考https://opendocs.alipay.com/mini/api/mapcontext.
*/
interface IMapContext {
/**
* 添加、删除、更新指定的标记(marker), https://opendocs.alipay.com/mini/00k9uj.
*/
changeMarkers: (options: {
add?: IMarker[];
update?: IMarker[];
remove?: Pick[];
success?: (result: unknown) => void;
}) => void;
/**
* 取地图东北角、西南角的经纬度,从而获取地图整体的视野范围。
* https://opendocs.alipay.com/mini/00nbqs.
*/
getRegion: (options: {
success?: (result: {
/**
* 西南角经纬度.
*/
southwest: my.ILocation;
/**
* 东北角经纬度.
*/
northeast: my.ILocation;
}) => void;
}) => void;
/**
* 缩放视野到指定可视区域.
* https://opendocs.alipay.com/mini/api/includepoints.
*/
includePoints: (params: {
/**
* 要显示在可视区域内的坐标点列表.
*/
points: my.ILocation[];
/**
* 坐标点形成的矩形边缘到地图边缘的距离。格式为 [上,右,下,左],如果数据只有一项,则上下左右的 padding 一致。
*/
padding?: [number] | [number, number, number, number];
}) => void;
}
interface IMapContextExtended {
/**
* 传递位置移动到指定位置, 否则移动到定位位置.
*
* @see https://opendocs.alipay.com/mini/api/ans8wt
*/
moveToLocation: (location?: my.ILocation) => void;
}
// //////////////////////////////////////////////////////////////////////////
// mini-types/types/api/open.d.ts
// //////////////////////////////////////////////////////////////////////////
interface INavigateToAlipayPageOptions {
/**
* 要跳转的支付宝官方业务,例如付款码,appCode: 'payCode',详见下方 appCode 参数说明。
* 跳转支付宝扫一扫、收到的红包页面、爱攒油页面、小程序快报生活号、蚂蚁森林、蚂蚁庄园、某只股票的详情页,请使用 appCode 属性。
* 支付宝客户端 10.1.62 版本开始支持。
* 个人小程序暂不支.
* alipayScan: 扫一扫, payCode: 付款码, antForest: 蚂蚁森林, antFarm: 蚂蚁庄园,
* stockDetail: 某只股票的详情页, redPacket: 收到的红包页, collectOil: 爱攒油,
* tinyAppSHH: 小程序快报生活号.
* 和`path`二选一.
* @see https://opendocs.alipay.com/mini/api/navigatetoalipaypage#appCode%20%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E
*/
appCode?:
| 'alipayScan' | 'payCode' | 'antForest' | 'antFarm'
| 'stockDetail' | 'redPacket' | 'collectOil' | 'tinyAppSHH' | string;
/**
* 和`appCode`二选一.
*/
// 如果重新修改库申明文件,使用了@ts-ignore,可能会导致node_modules中的源库类型检查错误,需要配合`skipLibCheck`为true来关闭所有申明文件类型检查.
// 先维持类型兼容模式修改,不采用skipLibCheck关闭所有申明文件类型检查,因为项目中可能也添加申明文件.
// @ts-ignore: All declarations of 'path' must have identical modifiers.ts(2687).
// Subsequent property declarations must have the same type.
// Property 'path' must be of type 'string', but here has type 'string | undefined'.ts(2717)
// path?: string;
}
// //////////////////////////////////////////////////////////////////////////
// 计算路径, https://opendocs.alipay.com/mini/api/calculate-route
// //////////////////////////////////////////////////////////////////////////
/**
* @see https://opendocs.alipay.com/mini/api/calculate-route#%E5%85%A5%E5%8F%82
*/
interface ICalculateRouteOptions {
/**
* 搜索类型, 可选取值为 "walk"、"bus"、"drive"、"ride"。默认值为 "walk"。
*/
searchType?: 'walk' | 'bus' | 'drive' | 'ride';
/**
* 起点纬度.
*/
startLat: number;
/**
* 起点经度.
*/
startLng: number;
/**
* 终点纬度.
*/
endLat: number;
/**
* 终点经度.
*/
endLng: number;
/**
* 途径点,仅驾车规划有效,即 searchType=“drive”时有效。
*/
throughPoints?: { lat: number; lng: number; }[];
/**
* 仅在驾车模式和公交模式支持,具体值见 mode 参数列表。
* 0 - 最快捷模式, 速度优先(时间)。
* 1 - 最经济模式.
* 2 - 最少换乘模式.
* 3 - 最少步行模式.
* 4 - 最舒适模式.
* 5 - 不乘地铁模式.
* 6 - 不走高速.
* 7 - 不走高速且避免收费.
* 8 - 躲避收费和拥堵.
* 9 - 不走高速且躲避收费和拥堵.
*/
mode?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
/**
* 公交模式下必填。传参可填写城市中文名称或城市名称拼音。例如: city:'hangzhou' 或 city:'杭州'。
*/
city?: string;
/**
* 公交跨城模式下必填。
*/
destinationCity?: string;
success: (
result: {
/**
* 距离,单位为米.
*/
distance: number;
/**
* 时间,单位为秒.
*/
duration: number;
}
) => void;
}
/**
* 计算路径,根据起点和终点的地理位置,智能规划最佳出行路线,并计算不同出行方式下的行动距离和所需时间。
* 模拟器可能不可用,请真机调试.
*
* @param options
* @see https://opendocs.alipay.com/mini/api/calculate-route
*/
function calculateRoute (options: ICalculateRouteOptions): void;
}