fix(typescript): tighten TypeScript typings and modernize project tooling configuration

This commit is contained in:
2026-05-01 16:30:12 +00:00
parent dc53984a77
commit d8b0da1826
13 changed files with 3964 additions and 5732 deletions
+11 -11
View File
@@ -3,16 +3,16 @@ export interface IResolve<T> {
}
export interface IReject {
(reason?: any): void;
(reason?: unknown): void;
}
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected';
export class Deferred<T> {
public promise: Promise<T>;
public resolve: IResolve<T>;
public reject: IReject;
public status: TDeferredStatus;
public resolve!: IResolve<T>;
public reject!: IReject;
public status!: TDeferredStatus;
public claimed = false;
public claim() {
if (this.claimed) {
@@ -21,8 +21,8 @@ export class Deferred<T> {
this.claimed = true;
}
public startedAt: number;
public stoppedAt: number;
public startedAt!: number;
public stoppedAt!: number;
public get duration(): number {
if (this.stoppedAt) {
return this.stoppedAt - this.startedAt;
@@ -33,12 +33,12 @@ export class Deferred<T> {
constructor() {
this.promise = new Promise<T>((resolve, reject) => {
this.resolve = (valueArg: T | PromiseLike<T>) => {
this.resolve = (valueArg?: T | PromiseLike<T>) => {
this.status = 'fulfilled';
this.stoppedAt = Date.now();
resolve(valueArg);
resolve(valueArg as T | PromiseLike<T>);
};
this.reject = (reason: any) => {
this.reject = (reason?: unknown) => {
this.status = 'rejected';
this.stoppedAt = Date.now();
reject(reason);
@@ -49,6 +49,6 @@ export class Deferred<T> {
}
}
export const defer = <T>() => {
export const defer = <T = void>() => {
return new Deferred<T>();
};
};