/** * `KeyOfType` returns keys of type `KeyType` from type `T`. It is similar * to TypeScript's `keyof` but additionally constrains by key type. */ export type KeyOfType = { [P in keyof Required]: Required[P] extends KeyType ? P : never; }[keyof T]; /** * `PickByType` creates a new type with properties from type `T` which * extend type `KeyType`. It is similar to TypeScript's `Pick` but selecting * by key type instead of key names */ export type PickByType = Pick>>; /** * `OmitByType` creates a new type without properties from type `T` which * extend type `KeyType`. It is similar to TypeScript's `Omit` but selecting * by key type instead of key name. */ export type OmitByType = Pick>>; /** * Result mimics the Rust's result type */ export type Result = Ok | Err; type NotError = T extends Error ? never : T; export declare function isOk(result: Result): result is Ok; export declare function isErr(result: Result): result is Err; export declare function ok(value: NotError): Ok; export declare function err(error: E): Err; export declare function tryCatch(op: () => NotError): Result; declare class Ok { private value; constructor(value: T); isOk(): this is Ok; isErr(): boolean; unwrap(): T; /** * Used mostly with tests */ unwrapOrThrow(): T; /** * Used mostly with tests */ unwrapErrOrThrow(): never; } declare class Err { private value; constructor(value: E); isOk(): boolean; isErr(): this is Err; unwrapErr(): E; /** * Used mostly with tests */ unwrapOrThrow(): never; /** * Used mostly with tests */ unwrapErrOrThrow(): E; } export {};