跳到主要内容

API 概览

TypeScript API Pro 提供了丰富的类型工具集,分为四个主要模块:

📦 模块结构

typescript-api-pro/
├── object/ # 对象类型工具
├── array/ # 数组类型工具
├── map/ # Map 类型工具
└── set/ # Set 类型工具

🔧 核心类型

基础类型

对象操作

依赖关系

数组操作

Map 操作

Set 操作

🎯 使用场景

类型安全的配置对象

import type { MutuallyWithObject, RequiredDependency } from 'typescript-api-pro';

interface DatabaseConfig {
host?: string;
port?: number;
ssl?: boolean;
}

// 确保 host 和 port 同时存在或同时不存在
type SafeDatabaseConfig = RequiredDependency<DatabaseConfig, 'host', 'port'>;

互斥选项

import type { MutuallyWithObject } from 'typescript-api-pro';

interface AuthOptions {
token: string;
username: string;
apiKey: string;
}

// 只能选择一种认证方式
type AuthMethod = MutuallyWithObject<AuthOptions>;

集合类型转换

import type { ArrayToSet, MapToObject, SetToArray } from 'typescript-api-pro';

// 数组转 Set(自动去重)
type UniqueColors = ArrayToSet<['red', 'blue', 'red', 'green']>; // Set<'red' | 'blue' | 'green'>

// Map 转对象
type ConfigObject = MapToObject<Map<'host' | 'port', string>>; // { host: string; port: string; }

📖 了解更多

选择特定的类型分类来了解更多详细信息和使用示例: