Skip to content

Commit

Permalink
feat(flatomise): generic type
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 8, 2024
1 parent aec6710 commit 3193b43
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/flatomise/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* Flat promise that can be resolved or rejected from outside.
*/
export interface Flatomise {
promise: Promise<void>;
resolve: () => void;
reject: () => void;
export interface Flatomise<T> {
promise: Promise<T>;
resolve: (value: T | PromiseLike<T>) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reject: (reason?: any) => void;
}

/**
Expand All @@ -21,11 +22,11 @@ export interface Flatomise {
* flatomise.resolve();
* ```
*/
export function newFlatomise(): Flatomise {
const flatomise: Partial<Flatomise> = {};
flatomise.promise = new Promise<void>((resolve, reject) => {
export function newFlatomise<T>(): Flatomise<T> {
const flatomise: Partial<Flatomise<T>> = {};
flatomise.promise = new Promise<T>((resolve, reject) => {
flatomise.resolve = resolve;
flatomise.reject = reject;
});
return flatomise as Flatomise;
return flatomise as Flatomise<T>;
}

0 comments on commit 3193b43

Please sign in to comment.