@actyx/sdk
Version:
Actyx SDK
69 lines (68 loc) • 3.11 kB
TypeScript
/**
* Base type for a tagged union with type as the tag field
*/
export declare type Tagged = {
readonly type: string;
};
/**
* Extract a case from a tagged union based on the (singleton) type of the tag
*/
export declare type SelectTag<T, Tag> = T extends {
type: Tag;
} ? T : never;
/**
* Type transform that makes a nested type partial, while
* leaving alone arrays, readonly arrays, functions and scalars
*/
export declare type DeepPartial<T> = T extends ReadonlyArray<any> ? T : T extends Function ? T : T extends object ? {
[K in keyof T]?: DeepPartial<T[K]>;
} : T;
export declare const todo: (...args: any[]) => never;
export declare const none: () => never;
/**
* Assert that from the type information, a piece of code can never be reached.
* If it’s still reached at runtime, this throws an Error.
* @public
*/
export declare const unreachable: (x?: never) => never;
/**
* Assert that from the type information, a certain statement can never be reached,
* while installing a default value to return in case the type information was wrong
* and the statement was in fact reached.
* @public
*/
export declare function unreachableOrElse<T>(_: never, t: T): T;
/**
* Avoids lint false positives like "Expression is always false. (strict-type-predicates)"
*/
export declare const lookup: <V>(m: {
[k: string]: V;
}, k: string) => V | undefined;
/**
* Helpers for dealing with "type X = { [ key: K]: Y | undefined }
*/
declare type RecordKey = string | number | symbol;
export declare type RWPartialRecord<K extends RecordKey, V> = {
[P in K]?: V;
};
export declare type PartialRecord<K extends RecordKey, V> = Readonly<RWPartialRecord<K, V>>;
export declare type PartialRecord2<K1 extends RecordKey, K2 extends RecordKey, V> = {
readonly [P in K1]?: {
readonly [T in K2]?: V;
};
};
export declare type RWKeyValueMap<T> = RWPartialRecord<string, T>;
export declare type KeyValueMap<T> = PartialRecord<string, T>;
export declare const isDefined: <T>(v: T) => v is Exclude<T, undefined>;
export declare const valuesOf: <V>(m: Readonly<RWPartialRecord<any, V>>) => Exclude<V, undefined>[];
export declare const keysOf: <K extends RecordKey, V>(m: Readonly<RWPartialRecord<K, V>>) => Extract<K, string>[];
export declare const entriesOf: <K extends RecordKey, V>(obj: Readonly<RWPartialRecord<K, V>>) => [Extract<K, string>, V][];
export declare const entriesOf2: <K1 extends RecordKey, K2 extends RecordKey, V>(m1: PartialRecord2<K1, K2, V>) => readonly [Extract<K1, string>, Extract<K2, string>, V][];
export declare const toKeyValueMapF: <T, U>(getKey: (v: T) => string, map: (v: T) => U, xs: readonly T[]) => Readonly<RWPartialRecord<string, U>>;
export declare const toKeyValueMap: <T, K extends keyof T>(key: K, xs: readonly T[]) => Readonly<RWPartialRecord<string, T>>;
export declare const tuple: <T extends any[]>(...data: T) => T;
export declare const PartialRecord: {
get<K extends RecordKey, V>(m: Readonly<RWPartialRecord<K, V>>, key: K): Readonly<RWPartialRecord<K, V>>[K];
};
export declare const noop: () => undefined;
export {};