Typings — ts-types
This module exports static TypeScript utility types. All declarations are compile-time-only — they produce no runtime code.
Import
import type {
IObject, IDict, IFunction, IAsyncFunction, IDeepPartial,
IConstructor, IBasicType, IAdvancedType, IElementOfArray,
IMaybeAsync, IMaybeArray, IToPromise,
IfIsAny, IfIsNever, IInstanceOf,
} from '@litert/utils-ts-types';Interface IObject
Source: index.ts
A marker interface representing any object value. Use in generic constraints where object would trigger ESLint's @typescript-eslint/ban-types rule.
interface IObject {}Example:
function merge<T extends IObject>(a: T, b: Partial<T>): T { ... }Type Alias IDict
Source: index.ts
A lightweight dictionary type. A simplified alias for Record<TKey, T>.
Definition
type IDict<
T = any,
TKey extends string | number | symbol = string | number | symbol
> = Record<TKey, T>;Parameters
| Parameter | Default | Description |
|---|---|---|
T | any | The type of values in the dictionary. |
TKey | string | number | symbol | The allowed key types. |
Example:
const data: IDict<number> = { a: 1, b: 2 };
const typed: IDict<string, string> = { key: 'value' };Type Alias IFunction
Source: index.ts
A utility type representing any function. Use in generic constraints where Function would be too broad.
Definition
type IFunction<
TArgs extends any[] = any,
TReturn = unknown
> = (...args: TArgs) => TReturn;Parameters
| Parameter | Default | Description |
|---|---|---|
TArgs | any[] | The argument types tuple. |
TReturn | unknown | The return type. |
Type Alias IAsyncFunction
Source: index.ts
A utility type representing any async function. Use in generic constraints for functions returning Promise.
Definition
type IAsyncFunction<
TArgs extends any[] = any,
TReturn = unknown
> = (...args: TArgs) => Promise<TReturn>;Parameters
| Parameter | Default | Description |
|---|---|---|
TArgs | any[] | The argument types tuple. |
TReturn | unknown | The resolved value type. |
Type Alias IDeepPartial
Source: index.ts
A recursive version of the built-in Partial<T> that makes all nested properties optional as well.
Definition
type IDeepPartial<T extends IObject> = {
[P in keyof T]?: T[P] extends IObject ? IDeepPartial<T[P]> : T[P];
};Example:
interface IConfig { server: { host: string; port: number }; debug: boolean; }
type IPartialConfig = IDeepPartial<IConfig>;
// { server?: { host?: string; port?: number }; debug?: boolean; }Type Alias IConstructor
Source: index.ts
Represents a class constructor function.
Definition
type IConstructor<T = unknown> = new (...args: any[]) => T;Parameters
| Parameter | Default | Description |
|---|---|---|
T | unknown | The instance type the constructor produces. |
Type Alias IBasicType
Source: index.ts
A union of all JavaScript primitive types.
Definition
type IBasicType = string | number | boolean | symbol | null | undefined | bigint;Type Alias IAdvancedType
Source: index.ts
A union of all non-primitive (object) types.
Definition
type IAdvancedType = IObject | any[] | IFunction | IConstructor;Type Alias IElementOfArray
Source: index.ts
Extracts the element type from an array type T.
Definition
type IElementOfArray<T extends any[]> = T extends Array<infer U> ? U : never;Example:
type TItem = IElementOfArray<string[]>; // string
type TNum = IElementOfArray<number[]>; // numberType Alias IMaybeAsync
Source: index.ts
A value that can be either T or Promise<T>. Useful for return types of functions that may be synchronous or asynchronous.
Definition
type IMaybeAsync<T> = Promise<T> | T;Type Alias IMaybeArray
Source: index.ts
A value that can be either a single T or an array T[]. Useful for function parameters that accept both forms.
Definition
type IMaybeArray<T> = T[] | T;Type Alias IToPromise
Source: index.ts
Wraps T in Promise<T>, unless T is already a Promise type (in which case it is returned unchanged).
Definition
type IToPromise<T> = T extends Promise<any> ? T : Promise<T>;Type Alias IfIsAny
Source: index.ts
A conditional type that resolves to TYes when T is any, and TNo otherwise.
Definition
type IfIsAny<T, TYes, TNo> = 0 extends (1 & T) ? TYes : TNo;Type Alias IfIsNever
Source: index.ts
A conditional type that resolves to TYes when T is never, and TNo otherwise.
Definition
type IfIsNever<T, TYes, TNo> = [T] extends [never] ? TYes : TNo;Type Alias IInstanceOf
Source: index.ts
Extracts the instance type from a constructor type T. This is the inverse operation of IConstructor.
Definition
type IInstanceOf<T> = T extends IConstructor<infer U> ? U : never;Example:
class MyClass {}
type IMyClassCtor = IConstructor<MyClass>;
type IMyClass = IInstanceOf<IMyClassCtor>; // MyClass