0.4.0 • Published 2 years ago
@shencom/typing v0.4.0
@shencom/typing
集成一些类型工具方法,公共接口的请求参数和响应数据类型
install
pnpm add @shencom/typing
# or
yarn add @shencom/typingUsage
Init
配置 tsconfig
// tsconfig.json
{
"compilerOptions": {
"types": ["@shencom/typing"]
}
}Basic Usage
import { DeepMutable, Unfurl } from '@shencom/typing';
// ...Typing
UTILS
Unfurl<T>: 展开对象类型interface User { name: string; profile: { address: string; }; } type User1 = Unfurl<User>;OneOf<T, U>: 类型二选一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: 移除readonlyinterface User { readonly name: string; readonly age: number; } type User1 = Mutable<User>; // type User1 = { name: string; age: number; }DeepMutable: 递归移除readonlyinterface User { readonly name: string; readonly profile: { readonly address: string; }; } type User1 = DeepMutable<User>; // type User1 = { name: string; profile: { address: string } };DeepParameters<T, Deep=1>: 获取第 N 层函数参数,默认第二层const A = (b: number) => {}; type B = DeepParameters<typeof A>; // [b: number] const AA = (b: number) => (c: number) => {}; type BB = DeepParameters<typeof AA>; // [c: number] const AAA = (b: number) => (c: number) => (d: number) => {}; type BBB = DeepParameters<typeof AAA, 2>; // [d: number]ReturnPromiseType<T>: 获取函数返回Promise泛型的值type A = (b: number) => Promise<boolean>; type B = ReturnPromiseType<A>; // booleanDictionary<T>: 对象添加索引类型const a = {}; a.a = 1; // 类型“{}”上不存在属性“a”。 const aa: Record<string, any> = {}; aa.a = 1;
SC
SC.APIQuery: 搜索类型Sorts: 筛选字段IndexQuery: index 接口查询参数类型IndexSorts: index 接口排序参数类型IndexInterface<T>: 分页接口IndexBodyInterface: index 接口参数类型ExportBodyInterface: export 接口参数类型
SC.FileInfo: 文件信息
SC.GisPoint: 点位信息
SC.OSSSign: oss 签名
SC.UserTokenRoot: 令牌信息SysInfo: 系统用户信息WxInfo: 微信用户信息RootInfo: 登录接口返回用户信息类型Info: 系统用户和微信用户并集
SC.CSMCategory: 栏目类型Articles: 内容类型
第三方
- 微信
JSSDK
0.4.0
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.3
2 years ago
0.3.0
2 years ago
0.2.1
3 years ago
0.2.0
3 years ago
0.2.1-alpha.0
3 years ago
0.2.1-alpha.1
3 years ago
0.1.6-alpha.1
3 years ago
0.1.6-alpha.0
3 years ago
0.1.6-alpha.2
3 years ago
0.1.5
3 years ago
0.1.0
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.0-alpha.1
3 years ago
0.1.0-alpha.0
3 years ago