Skip to content

Documentation / @cashconnect-js/core / primitives/type-utils

Promisable

ts
type Promisable<T> = Promise<T> | T;

Defined in: cashconnect-js/packages/core/src/primitives/type-utils.ts:11

Represents a value that can be either the type itself or a Promise of that type. Useful for functions that can return either synchronously or asynchronously.

Type Parameters

Type Parameter
T

Example

ts
function getData(): Promisable<string> {
  // Can return either a string directly or a Promise<string>
  return Math.random() > 0.5 ? "data" : Promise.resolve("data");
}

Prettify

ts
type Prettify<T> = { [K in keyof T]: T[K] } & object;

Defined in: cashconnect-js/packages/core/src/primitives/type-utils.ts:24

Transforms a complex type into a simplified representation in intellisense. Helps with readability by flattening intersection types into a single object type.

Type Parameters

Type Parameter
T

Example

ts
type A = { a: string };
type B = { b: number };
// Without Prettify: type C = A & B
// With Prettify: type C = { a: string; b: number }
type C = Prettify<A & B>;

Arrayable

ts
type Arrayable<T> = T | T[];

Defined in: cashconnect-js/packages/core/src/primitives/type-utils.ts:43

Represents a value that can be either a single item or an array of that item type. Useful for parameters that accept either a single value or multiple values.

Type Parameters

Type Parameter
T

Example

ts
function process(input: Arrayable<string>): void {
  // Convert to array if not already
  const items = Array.isArray(input) ? input : [input];
  // Process each item...
}

// Both usages are valid:
process("item");
process(["item1", "item2"]);