UNPKG

1.27 kBTypeScriptView Raw
1/**
2 * A callback function that accepts an error or a result.
3 * @public
4 */
5export interface Callback<T> {
6 (error: Error, result?: never): void;
7 (error: null, result: T): void;
8}
9/**
10 * A callback function that only accepts an error.
11 * @public
12 */
13export interface ErrorCallback {
14 (error: Error | null): void;
15}
16/**
17 * The inverse of NonNullable<T>.
18 * @public
19 */
20export type Nullable<T> = T | null | undefined;
21/** Wrapped `Object.prototype.toString`, so that you don't need to remember to use `.call()`. */
22export declare const objectToString: (obj: unknown) => string;
23/** Safely converts any value to string, using the value's own `toString` when available. */
24export declare const safeToString: (val: unknown) => string;
25/** Utility object for promise/callback interop. */
26export interface PromiseCallback<T> {
27 promise: Promise<T>;
28 callback: Callback<T>;
29 resolve: (value: T) => Promise<T>;
30 reject: (error: Error) => Promise<T>;
31}
32/** Converts a callback into a utility object where either a callback or a promise can be used. */
33export declare function createPromiseCallback<T>(cb?: Callback<T>): PromiseCallback<T>;
34export declare function inOperator<K extends string, T extends object>(k: K, o: T): o is T & Record<K, unknown>;