Types
@ripl/utilities
Shared TypeScript type definitions.
Overview
Interfaces: Disposable
Type Aliases: AnyObject · AnyFunction · AnyAsyncFunction · OneOrMore · Predicate · Indexer · Merge · UnionToIntersection · IfEquals · GetReadonlyKeys · GetMutableKeys
Disposable interface
A resource that can be disposed to release underlying subscriptions or handles.
interface Disposable {
dispose: () => void;
}Properties:
| Property | Type | Description |
|---|---|---|
dispose | () => void |
AnyObject type
A loosely-typed object with string, number, or symbol keys.
type AnyObject = { [key: PropertyKey]: unknown };AnyFunction type
A loosely-typed function signature that accepts and returns anything.
type AnyFunction = (...args: any[]) => any;AnyAsyncFunction type
A loosely-typed async function signature.
type AnyAsyncFunction = (...args: any[]) => any;OneOrMore type
Represents a single value or an array of values.
type OneOrMore<TValue> = TValue | TValue[];Predicate type
A comparison function that tests whether two values match.
type Predicate<TLeft, TRight = TLeft> = (left: TLeft, right: TRight) => boolean;Indexer type
Derives a grouping key from a value.
type Indexer<TValue> = (value: TValue) => PropertyKey;Merge type
Merges two types, with properties in TB overriding those in TA.
type Merge<TA, TB> = Omit<TA, keyof TB> & TB;UnionToIntersection type
Converts a union type to an intersection type.
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends ((arg: infer I) => void) ? I : never;IfEquals type
Conditional type that resolves to A if X and Y are identical, otherwise B.
type IfEquals<X, Y, A = X, B = never> =
(<TValue>() => TValue extends X ? 1 : 2) extends
(<TValue>() => TValue extends Y ? 1 : 2) ? A : B;GetReadonlyKeys type
Extracts the readonly property keys from an object type.
type GetReadonlyKeys<TValue extends object> = {
[TKey in keyof TValue]-?: IfEquals<{ [Q in TKey]: TValue[TKey] }, { -readonly [Q in TKey]: TValue[TKey] }, never, TKey>
}[keyof TValue];GetMutableKeys type
Extracts the mutable (non-readonly) property keys from an object type.
type GetMutableKeys<TValue extends object> = {
[TKey in keyof TValue]-?: IfEquals<{ [Q in TKey]: TValue[TKey] }, { -readonly [Q in TKey]: TValue[TKey] }, TKey>;
}[keyof TValue];