全面覆盖
700+ 实用类型工具,涵盖核心操作、企业级模式、实时系统、微服务等。
import type {
PickRequired, DeepPartial, Sort, IsArray,
GraphQLQuery, WebSocketMessage, EventBus, Workflow,
Tensor, Model, Maybe, Either, Infer
} from 'uni-types'
// 核心:将指定属性变为必需
interface User {
name?: string
age?: number
email: string
}
type RequiredUser = PickRequired<User, 'name' | 'age'>
// 深度可选,处理嵌套对象
interface Config {
database: { host: string; port: number }
}
type PartialConfig = DeepPartial<Config>
// 类型级别排序算法
type Sorted = Sort<[3, 1, 4, 1, 5]> // [1, 1, 3, 4, 5]
// GraphQL 查询类型 (v1.5.0)
type GetUserQuery = GraphQLQuery<{ id: string }, { userId: string }>
// WebSocket 消息类型 (v1.5.0)
type ChatMessage = WebSocketMessage<{ text: string; userId: string }>
// 事件总线类型 (v1.5.0)
type AppEvents = EventBus<{ userCreated: { id: string }; orderPlaced: { orderId: string } }>
// 工作流类型 (v1.5.0)
type OrderWorkflow = Workflow<{ orderId: string; status: string }>
// AI/ML 张量类型 (v1.6.0)
type ImageTensor = Tensor<[224, 224, 3], 'float32'>
// 函数式编程 (v1.6.0)
type OptionalValue = Maybe<string> // Some<string> | None
type Result = Either<Error, string> // Left<Error> | Right<string>
// 类型推断 (v1.6.0)
type PromiseValue = Infer<Promise<string>> // string
// 元编程 (v1.7.0)
type Analysis = AnalyzeType<{ nested: { deep: string } }>
type Visual = VisualizeType<{ a: number; b: string }>
// 装饰器类型 (v1.7.0)
type LoggedMethod = MethodDecorator<(arg: string) => void>
// 类型生成 (v1.7.0)
type GeneratedUser = GenerateFromSchema<{ name: 'string'; age: 'number' }>
// 加密类型 (v1.7.0)
type Sha256Hash = HashOutput<256>
// 日期时间类型 (v1.7.0)
type UserDuration = Duration<{ hours: number; minutes: number }>
// 类型级数学 (v1.7.0)
type Sum = Add<10, 20> // number
type IsSevenPrime = IsPrime<7> // true
// 类型级搜索 (v1.7.0)
type UniqueNumbers = Unique<[1, 2, 2, 3, 3]> // [1, 2, 3]
type Intersect = Intersection<[1, 2, 3], [2, 3, 4]> // [2, 3]零依赖
轻量级,无外部依赖。纯粹的 TypeScript 类型魔法。
TypeScript 5+
使用最新的 TypeScript 特性,提供最佳类型推导。
::: success 企业级就绪 700+ 类型涵盖微服务、事件驱动架构、工作流引擎和实时系统。 :::