Skip to content

Commit

Permalink
ts类型优化
Browse files Browse the repository at this point in the history
  • Loading branch information
LAMMUpro committed Jan 14, 2024
1 parent 0e0342d commit 7f79a47
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@

/**
* 基础对象类型
*/
interface BaseObj<T = string|number|boolean> {
[key: string]: T
}

/**
* 提取函数参数的类型
*/
type ParamsType<T> = T extends (...args: infer P) => any ? P : never;

/**
* 分页类型
*/
interface PageInfo {
/** 每页数据 */
pageSize: number
Expand All @@ -12,23 +22,33 @@ interface PageInfo {
totalCount?: number
}

/** 请求方法 */
/**
* 请求方法
*/
type requestMethods = "GET" | "POST" | "DELETE" | "PUT" | "PATCH" | "OPTIONS";

type ApiResponse = {
/** 1表示成功, -1表示失败 */
code: 1 | -1
/** 状态码, 0表示无异常, 其他为错误异常码 */
status: 0 | number
/**
* 响应格式
*/
type ApiResponse<T> = {
/** 是否成功 */
success: true
/** 数据 */
data: T
} | {
/** 是否成功 */
success: false
/** 错误响应码 */
code: string
/** 信息 */
msg: 'ok' | string
msg: string
/** 弹窗时间 */
msgTimeout?: number
/** 成功为json格式数据, 失败可能为null */
data?: BaseObj<any>
}

/** 两个类型是否相等 */
/**
* 判断两个类型是否相等
*/
type IsEqual<T, U> =
(<T1>() => T1 extends T ? 1 : 2) extends
(<T2>() => T2 extends U ? 1 : 2)
Expand Down

0 comments on commit 7f79a47

Please sign in to comment.