@shencom/typing
v0.4.0
Published
shencom typescript types
Downloads
59
Readme
@shencom/typing
集成一些类型工具方法,公共接口的请求参数和响应数据类型
install
pnpm add @shencom/typing
# or
yarn add @shencom/typing
Usage
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
: 移除readonly
interface User { readonly name: string; readonly age: number; } type User1 = Mutable<User>; // type User1 = { name: string; age: number; }
DeepMutable
: 递归移除readonly
interface 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>; // boolean
Dictionary<T>
: 对象添加索引类型const a = {}; a.a = 1; // 类型“{}”上不存在属性“a”。 const aa: Record<string, any> = {}; aa.a = 1;
SC
SC.API
Query
: 搜索类型Sorts
: 筛选字段IndexQuery
: index 接口查询参数类型IndexSorts
: index 接口排序参数类型IndexInterface<T>
: 分页接口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