API Overview
TypeScript API Pro provides a rich set of type utilities organized into four main modules:
đĻ Module Structureâ
typescript-api-pro/
âââ object/ # Object type utilities
âââ array/ # Array type utilities
âââ map/ # Map type utilities
âââ set/ # Set type utilities
âââ string/ # String type utilities
đ§ Core Typesâ
Basic Typesâ
PropertyKey- Object property key typeAnyObject<T>- Generic object type
Object Operationsâ
ValueOf<T>- Extract object value typesKeyOf<T>- Extract object key typesGeneric<R, K, T>- Override object property typeOmitByObject<T, U>- Exclude properties based on object structure
Dependency Relationshipsâ
RequiredDependency<T, K, D>- Property dependency relationshipMutuallyWithObject<T>- Mutually exclusive object propertiesMutually<T, K, O>- Two-property mutual exclusion
Array Operationsâ
ArrayItem<T>- Extract array element type
Map Operationsâ
MapKeyOf<T>- Extract Map key typeMapValueOf<T>- Extract Map value typeMapToObject<T>- Convert Map to objectObjectToMap<T>- Convert object to MapOmitMapKey<T, K>- Exclude Map keysPickMapKey<T, K>- Select Map keys
Set Operationsâ
SetValueOf<T>- Extract Set element typeOmitSetValue<T, V>- Exclude Set valuesPickSetValue<T, V>- Select Set valuesArrayToSet<T>- Convert array to SetSetToArray<T>- Convert Set to array
String Operationsâ
Camel2SnakeCase<T, U>- Convert camelCase to snake_case
đ¯ Use Casesâ
Type-Safe Configuration Objectsâ
import type { MutuallyWithObject, RequiredDependency } from 'typescript-api-pro';
interface DatabaseConfig {
host?: string;
port?: number;
ssl?: boolean;
}
// Ensure host and port exist together or not at all
type SafeDatabaseConfig = RequiredDependency<DatabaseConfig, 'host', 'port'>;
Mutually Exclusive Optionsâ
import type { MutuallyWithObject } from 'typescript-api-pro';
interface AuthOptions {
token: string;
username: string;
apiKey: string;
}
// Only one authentication method can be selected
type AuthMethod = MutuallyWithObject<AuthOptions>;
Collection Type Conversionâ
import type { ArrayToSet, MapToObject, SetToArray } from 'typescript-api-pro';
// Array to Set (automatic deduplication)
type UniqueColors = ArrayToSet<['red', 'blue', 'red', 'green']>; // Set<'red' | 'blue' | 'green'>
// Map to object
type ConfigObject = MapToObject<Map<'host' | 'port', string>>; // { host: string; port: string; }
String Transformationâ
import type { Camel2SnakeCase } from 'typescript-api-pro';
// Convert camelCase to UPPER_SNAKE_CASE
type SnakeCaseKey = Camel2SnakeCase<'userName'>; // 'USER_NAME'
// Convert to lowercase snake_case
type LowerSnakeCase = Camel2SnakeCase<'userId', false>; // 'user_id'
đ Learn Moreâ
Choose a specific type category to learn more details and usage examples: