shencom typescript types
> 集成一些类型工具方法,公共接口的请求参数和响应数据类型
``sh
pnpm add @shencom/typing
yarn add @shencom/typing
`
配置 tsconfig
`json`
// tsconfig.json
{
"compilerOptions": {
"types": ["@shencom/typing"]
}
}
`ts
import { DeepMutable, Unfurl } from '@shencom/typing';
// ...
`
- Unfurl: 展开对象类型
`ts`
interface User {
name: string;
profile: {
address: string;
};
}
type User1 = Unfurl
- OneOf: 类型二选一
`ts
const A: OneOf<{ a: string }, { b: string }> = {
a: '',
};
// or
const B: OneOf<{ a: string }, { b: string }> = {
b: '',
};
// error 不能将类型“{ a: string; b: string; }”分配给类型
const AA: OneOf<{ a: string }, { b: string }> = {
a: '',
b: '',
};
`
- Mutable: 移除 readonly
`ts
interface User {
readonly name: string;
readonly age: number;
}
type User1 = Mutable
`
- DeepMutable: 递归移除 readonly
`ts`
interface User {
readonly name: string;
readonly profile: {
readonly address: string;
};
}
type User1 = DeepMutable
- DeepParameters: 获取第 N 层函数参数,默认第二层
`ts
const A = (b: number) => {};
type B = DeepParameters
const AA = (b: number) => (c: number) => {};
type BB = DeepParameters
const AAA = (b: number) => (c: number) => (d: number) => {};
type BBB = DeepParameters
`
- ReturnPromiseType: 获取函数返回 Promise 泛型的值
`ts
type A = (b: number) => Promise
type B = ReturnPromiseType; // boolean
`
- Dictionary: 对象添加索引类型
`ts
const a = {};
a.a = 1; // 类型“{}”上不存在属性“a”。
const aa: Record
aa.a = 1;
`
- SC.APIQuery
- : 搜索类型Sorts
- : 筛选字段IndexQuery
- : index 接口查询参数类型IndexSorts
- : index 接口排序参数类型IndexInterface
- : 分页接口IndexBodyInterface
- : index 接口参数类型ExportBodyInterface
- : export 接口参数类型SC.File
- Info
- : 文件信息SC.Gis
- Point
- : 点位信息SC.OSS
- Sign
- : oss 签名SC.User
- TokenRoot
- : 令牌信息SysInfo
- : 系统用户信息WxInfo
- : 微信用户信息RootInfo
- : 登录接口返回用户信息类型Info
- : 系统用户和微信用户并集SC.CSM
- Category
- : 栏目类型Articles
- : 内容类型
- 微信 JSSDK`