UNPKG

1.57 kBTypeScriptView Raw
1interface PromiseStatus<T> {
2 isPending: () => boolean;
3 isRejected: () => boolean;
4 isFulfilled: () => boolean;
5 getFullFilledValue: () => T;
6}
7/**
8 * This function allow you to modify a JS Promise by adding some status properties.
9 * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
10 * But modified according to the specs of promises : https://promisesaplus.com/
11 */
12export declare const makeQuerablePromise: <T>(promise: Promise<T>) => PromiseStatus<T>;
13/**
14 * Simple implementation of the deferred pattern.
15 * An object that exposes a promise and functions to resolve and reject it.
16 */
17export declare class Deferred<T = void> {
18 resolve: (value: T | PromiseLike<T>) => void;
19 reject: (err?: any) => void;
20 promise: Promise<T>;
21}
22export declare const equalSet: (as: Set<any>, bs: Set<any>) => boolean;
23/**
24 * Nicely typed aliases for some `Object` Methods
25 * - PSA: Don't mutate `yourObject`s
26 * - Numerical keys are BAD, resolve that issue upstream
27 * - Discussion: https://stackoverflow.com/a/65117465/565877
28 */
29export declare const ObjectTyped: {
30 /**
31 * Object.keys, but with nice typing (`Array<keyof T>`)
32 */
33 keys: <T extends {}>(yourObject: T) => (keyof T)[];
34 /**
35 * Object.values, but with nice typing
36 */
37 values: <T_1 extends {}>(yourObject: T_1) => T_1[keyof T_1][];
38 /**
39 * Object.entries, but with nice typing
40 */
41 entries: <T_2 extends {}>(yourObject: T_2) => [keyof T_2, T_2[keyof T_2]][];
42};
43export {};