Skip to content

Commit

Permalink
fix(type): update type of my.request
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKonka authored and ZakaryCode committed Jul 17, 2023
1 parent dff7c4b commit 085259f
Showing 1 changed file with 64 additions and 19 deletions.
83 changes: 64 additions & 19 deletions packages/taro/types/api/network/request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ declare module '../../index' {
header?: TaroGeneral.IAnyObject
/** 超时时间,单位为毫秒
* @default 2000
* @supported weapp, h5, tt
* @supported weapp, h5, tt, alipay
*/
timeout?: number
/** HTTP 请求方法
* @default GET
* @default "GET"
*/
method?: keyof Method
/** 返回的数据格式 */
Expand Down Expand Up @@ -60,6 +60,19 @@ declare module '../../index' {
* @supported weapp
*/
forceCellularNetwork?: boolean
/**
* headers 中设置 cookie 字段是否生效。如果为 false,则 headers 中的 cookie 字段将被忽略,请求头中将包含服务端上一次返回的 cookie(如果有)。
* @default false
* @supported alipay 支付宝: 10.2.33+
*/
enableCookie?: boolean
/**
* referer 策略,用于控制当前请求 header 对象中 referer 字段格式。该参数默认值可通过 app.json 中的配置进行修改。
* @default "querystring"
* @supported alipay 支付宝: 10.3.50+ APPX: 2.8.7 开发者工具: 3.5.1
* @see https://opendocs.alipay.com/mini/api/owycmh#referrerStrategy%20%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E
*/
referrerStrategy?: keyof ReferrerStrategy
/** 接口调用成功的回调函数 */
success?: (result: SuccessCallbackResult<T>) => void
/** 接口调用失败的回调函数 */
Expand Down Expand Up @@ -126,7 +139,8 @@ declare module '../../index' {
storeCheck?(): boolean
}

interface SuccessCallbackResult<T extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any> extends TaroGeneral.CallbackResult {
interface SuccessCallbackResult<T extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any>
extends TaroGeneral.CallbackResult {
/** 开发者服务器返回的数据 */
data: T
/** 开发者服务器返回的 HTTP Response Header */
Expand All @@ -141,10 +155,26 @@ declare module '../../index' {

/** 返回的数据格式 */
interface DataType {
/** 返回的数据为 JSON,返回后会对返回的数据进行一次 JSON.parse
/**
* 返回的数据为 JSON,返回后会对返回的数据进行一次 JSON.parse
* 其他: 不对返回的内容进行 JSON.parse
*/
json
/**
* 返回的数据为文本字符串
* @supported alipay
*/
text
/**
* 返回的数据将转换为 base64 格式字符串
* @supported alipay
*/
base64
/**
* 返回的数据将保持 ArrayBuffer 数据
* @supported alipay 支付宝: 10.1.70+
*/
arraybuffer
}

/** HTTP 请求方法 */
Expand Down Expand Up @@ -208,6 +238,21 @@ declare module '../../index' {
/** 浏览器在其HTTP缓存中寻找匹配的请求 */
'only-if-cached'
}
/** referer 策略 */
interface ReferrerStrategy {
/**
* referer 值为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html
*/
index
/**
* 保留 page(pages/xxx/yyy),referer 值为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page}
*/
page
/**
* 默认值。会将发起请求时所在页面的 URL 作为 referer 值,会保留 page(pages/xxx/yyy)和 querystring(x=1&y=2)并可能有框架添加的其他参数,referer 值为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page}?{querysrtring}{框架其他参数}
*/
querystring
}
}

/** 网络请求任务对象
Expand Down Expand Up @@ -268,38 +313,38 @@ declare module '../../index' {
* @supported weapp, tt
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.abort.html
*/
abort (): void
abort(): void
/** 监听 HTTP Response Header 事件。会比请求完成事件更早
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onHeadersReceived.html
*/
onHeadersReceived (
onHeadersReceived(
/** HTTP Response Header 事件的回调函数 */
callback: RequestTask.onHeadersReceived.Callback,
callback: RequestTask.onHeadersReceived.Callback
): void
/** 取消监听 HTTP Response Header 事件
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offHeadersReceived.html
*/
offHeadersReceived (
offHeadersReceived(
/** HTTP Response Header 事件的回调函数 */
callback: RequestTask.onHeadersReceived.Callback,
callback: RequestTask.onHeadersReceived.Callback
): void
/** 监听 Transfer-Encoding Chunk Received 事件。当接收到新的chunk时触发。
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onChunkReceived.html
*/
onChunkReceived (
onChunkReceived(
/** Transfer-Encoding Chunk Received 事件的回调函数 */
callback: RequestTask.onChunkReceived.Callback,
callback: RequestTask.onChunkReceived.Callback
): void
/** 移除 Transfer-Encoding Chunk Received 事件的监听函数
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offChunkReceived.html
*/
offChunkReceived (
offChunkReceived(
/** Transfer-Encoding Chunk Received 事件的回调函数 */
callback: RequestTask.onChunkReceived.Callback,
callback: RequestTask.onChunkReceived.Callback
): void
}

Expand Down Expand Up @@ -331,14 +376,14 @@ declare module '../../index' {
index: number
requestParams: RequestParams
interceptors: interceptor[]
proceed (requestParams: RequestParams): any
proceed(requestParams: RequestParams): any
}

/** @ignore */
interface interceptors {
logInterceptor (chain: Chain): Promise<any>
logInterceptor(chain: Chain): Promise<any>

timeoutInterceptor (chain: Chain): Promise<any>
timeoutInterceptor(chain: Chain): Promise<any>
}

interface TaroStatic {
Expand Down Expand Up @@ -374,7 +419,7 @@ declare module '../../index' {
* ```
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
*/
request<T = any, U = any> (option: request.Option<T, U>): RequestTask<T>
request<T = any, U = any>(option: request.Option<T, U>): RequestTask<T>

/** 可以使用拦截器在请求发出前或发出后做一些额外操作。
*
Expand Down Expand Up @@ -408,7 +453,7 @@ declare module '../../index' {
* ```
* @since 1.2.16
*/
addInterceptor (interceptor: interceptor): any
addInterceptor(interceptor: interceptor): any

/** 清除所有拦截器
* @example
Expand All @@ -417,7 +462,7 @@ declare module '../../index' {
* ```
* @supported weapp, h5, alipay, swan, tt, qq
*/
cleanInterceptors (): void
cleanInterceptors(): void

interceptors: interceptors
}
Expand Down

0 comments on commit 085259f

Please sign in to comment.