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
+39
View File
@@ -0,0 +1,39 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartpromise",
"shortDescription": "promise and deferred utilities",
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
"npmPackagename": "@push.rocks/smartpromise",
"license": "MIT",
"keywords": [
"promise",
"deferred",
"async",
"promisify",
"cumulative deferred",
"timeout",
"typescript",
"asynchronous",
"utilities"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+8
View File
@@ -1,5 +1,13 @@
# Changelog # Changelog
## 2026-05-01 - 4.2.4 - fix(typescript)
tighten TypeScript typings and modernize project tooling configuration
- replace custom async map implementation with Promise.all while preserving result order
- add explicit generic overloads and unknown-based typings across promise utilities and deferred classes
- enable noImplicitAny and update tests to use the current tstest tapbundle import
- refresh package and project config for newer git.zone tooling and npm release settings
## 2025-02-20 - 4.2.3 - fix(test) ## 2025-02-20 - 4.2.3 - fix(test)
Refactor test suite for improved readability and maintainability. Refactor test suite for improved readability and maintainability.
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+14 -6
View File
@@ -1,14 +1,11 @@
{ {
"npmci": { "@git.zone/cli": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "code.foss.global", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartpromise", "gitrepo": "smartpromise",
"shortDescription": "promise and deferred utilities",
"description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.", "description": "A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.",
"npmPackagename": "@push.rocks/smartpromise", "npmPackagename": "@push.rocks/smartpromise",
"license": "MIT", "license": "MIT",
@@ -23,9 +20,20 @@
"asynchronous", "asynchronous",
"utilities" "utilities"
] ]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
} }
}, },
"tsdoc": { "@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n" "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
} }
} }
+11 -9
View File
@@ -6,26 +6,26 @@
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "tstest test/ --web",
"build": "(tsbuild --web --allowimplicitany)", "format": "gitzone format",
"build": "tsbuild --web",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://code.foss.global/push.rocks/smartpromise.git" "url": "https://code.foss.global/push.rocks/smartpromise.git"
}, },
"author": "Lossless GmbH", "author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/smartq/issues" "url": "https://code.foss.global/push.rocks/smartpromise/issues"
}, },
"homepage": "https://code.foss.global/push.rocks/smartpromise", "homepage": "https://code.foss.global/push.rocks/smartpromise",
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.2.0", "@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsrun": "^1.3.3", "@git.zone/tsrun": "^2.0.3",
"@git.zone/tstest": "^1.0.92", "@git.zone/tstest": "^3.6.3",
"@push.rocks/tapbundle": "^5.5.6", "@types/node": "^25.6.0"
"@types/node": "^22.10.10"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -36,6 +36,8 @@
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
".smartconfig.json",
"license",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
], ],
+3829 -5666
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,4 +1,4 @@
import { expect, tap } from '@push.rocks/tapbundle'; import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartpromise from '../ts/index.js'; import * as smartpromise from '../ts/index.js';
tap.test('should return a Deferred for .defer()', async () => { tap.test('should return a Deferred for .defer()', async () => {
@@ -17,7 +17,7 @@ tap.test('should let types flow through the Promise', async () => {
tap.test('should map callbacks', async () => { tap.test('should map callbacks', async () => {
const inputArray = ['hi', 'awesome']; const inputArray = ['hi', 'awesome'];
const myPromisified = async (myInput) => { const myPromisified = async (myInput: string) => {
return myInput; return myInput;
}; };
const result = await smartpromise.map(inputArray, myPromisified); const result = await smartpromise.map(inputArray, myPromisified);
+1 -1
View File
@@ -1,5 +1,5 @@
import * as smartpromise from '../ts/index.js'; import * as smartpromise from '../ts/index.js';
import { tap, expect } from '@push.rocks/tapbundle'; import { tap, expect } from '@git.zone/tstest/tapbundle';
tap.test('simple deferred should resolve with correct value', async () => { tap.test('simple deferred should resolve with correct value', async () => {
const done = smartpromise.defer<string>(); const done = smartpromise.defer<string>();
+1 -1
View File
@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartpromise', name: '@push.rocks/smartpromise',
version: '4.2.3', version: '4.2.4',
description: 'A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.' description: 'A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.'
} }
+18 -24
View File
@@ -3,23 +3,24 @@ import { defer } from './smartpromise.classes.deferred.js';
export * from './smartpromise.classes.cumulativedeferred.js'; export * from './smartpromise.classes.cumulativedeferred.js';
export * from './smartpromise.classes.deferred.js'; export * from './smartpromise.classes.deferred.js';
export function resolvedPromise(): Promise<void>;
export function resolvedPromise<T>(value: T): Promise<T>;
/** /**
* Creates a new resolved promise for the provided value. * Creates a new resolved promise for the provided value.
*/ */
export const resolvedPromise = <T>(value?: T): Promise<T> => { export function resolvedPromise<T>(value?: T): Promise<T | void> {
return Promise.resolve(value); return Promise.resolve(value);
}; }
/** /**
* Creates a new rejected promise for the provided reason. * Creates a new rejected promise for the provided reason.
*/ */
export const rejectedPromise = (err) => { export const rejectedPromise = (err: unknown): Promise<never> => {
return Promise.reject(err); return Promise.reject(err);
}; };
interface IAsyncFunction<T> { interface IAsyncFunction<TInput, TOutput> {
(someArg: T): Promise<T>; (someArg: TInput): Promise<TOutput>;
} }
/** /**
@@ -28,26 +29,19 @@ interface IAsyncFunction<T> {
* @param inputArg * @param inputArg
* @param functionArg * @param functionArg
*/ */
export const map = async <T>(inputArg: T[], functionArg: IAsyncFunction<T>) => { export const map = async <TInput, TOutput = TInput>(
const promiseArray: Promise<any>[] = []; inputArg: TInput[],
const resultArray = []; functionArg: IAsyncFunction<TInput, TOutput>
for (const item of inputArg) { ): Promise<TOutput[]> => {
const promise: Promise<any> = functionArg(item); return Promise.all(inputArg.map(functionArg));
promiseArray.push(promise);
promise.then((x) => {
resultArray.push(x);
});
}
await Promise.all(promiseArray);
return resultArray;
}; };
export const timeoutWrap = async <T = any>( export const timeoutWrap = async <T = unknown>(
promiseArg: Promise<T>, promiseArg: Promise<T>,
timeoutInMsArg: number, timeoutInMsArg: number,
rejectArg = true rejectArg = true
) => { ): Promise<T | null> => {
return new Promise<T>((resolve, reject) => { return new Promise<T | null>((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
if (rejectArg) { if (rejectArg) {
reject(new Error('timeout')); reject(new Error('timeout'));
@@ -59,14 +53,14 @@ export const timeoutWrap = async <T = any>(
}); });
}; };
export const timeoutAndContinue = async <T = any>( export const timeoutAndContinue = async <T = unknown>(
promiseArg: Promise<T>, promiseArg: Promise<T>,
timeoutInMsArg = 60000 timeoutInMsArg = 60000
) => { ): Promise<T | null> => {
return timeoutWrap(promiseArg, timeoutInMsArg, false); return timeoutWrap(promiseArg, timeoutInMsArg, false);
}; };
export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]) => { export const getFirstTrueOrFalse = async (promisesArg: Promise<boolean>[]): Promise<boolean> => {
const done = defer<boolean>(); const done = defer<boolean>();
for (const promiseArg of promisesArg) { for (const promiseArg of promisesArg) {
promiseArg.then((resultArg) => { promiseArg.then((resultArg) => {
@@ -1,8 +1,8 @@
import { defer } from "./smartpromise.classes.deferred.js"; import { defer } from './smartpromise.classes.deferred.js';
export class CumulativeDeferred { export class CumulativeDeferred {
private accumulatedPromises: Promise<any>[] = []; private accumulatedPromises: Promise<unknown>[] = [];
private deferred = defer(); private deferred = defer<void>();
public promise = this.deferred.promise; public promise = this.deferred.promise;
constructor() { constructor() {
@@ -16,17 +16,16 @@ export class CumulativeDeferred {
} }
public subDefer() { public subDefer() {
const done = defer(); const done = defer<void>();
this.addPromise(done.promise); this.addPromise(done.promise);
return done; return done;
} }
public addPromise(promiseArg: Promise<any>) { public addPromise(promiseArg: Promise<unknown>): void {
this.accumulatedPromises.push(promiseArg); this.accumulatedPromises.push(promiseArg);
} }
} }
export const cumulativeDefer = () => { export const cumulativeDefer = () => {
return new CumulativeDeferred(); return new CumulativeDeferred();
} };
+10 -10
View File
@@ -3,16 +3,16 @@ export interface IResolve<T> {
} }
export interface IReject { export interface IReject {
(reason?: any): void; (reason?: unknown): void;
} }
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected'; export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected';
export class Deferred<T> { export class Deferred<T> {
public promise: Promise<T>; public promise: Promise<T>;
public resolve: IResolve<T>; public resolve!: IResolve<T>;
public reject: IReject; public reject!: IReject;
public status: TDeferredStatus; public status!: TDeferredStatus;
public claimed = false; public claimed = false;
public claim() { public claim() {
if (this.claimed) { if (this.claimed) {
@@ -21,8 +21,8 @@ export class Deferred<T> {
this.claimed = true; this.claimed = true;
} }
public startedAt: number; public startedAt!: number;
public stoppedAt: number; public stoppedAt!: number;
public get duration(): number { public get duration(): number {
if (this.stoppedAt) { if (this.stoppedAt) {
return this.stoppedAt - this.startedAt; return this.stoppedAt - this.startedAt;
@@ -33,12 +33,12 @@ export class Deferred<T> {
constructor() { constructor() {
this.promise = new Promise<T>((resolve, reject) => { this.promise = new Promise<T>((resolve, reject) => {
this.resolve = (valueArg: T | PromiseLike<T>) => { this.resolve = (valueArg?: T | PromiseLike<T>) => {
this.status = 'fulfilled'; this.status = 'fulfilled';
this.stoppedAt = Date.now(); this.stoppedAt = Date.now();
resolve(valueArg); resolve(valueArg as T | PromiseLike<T>);
}; };
this.reject = (reason: any) => { this.reject = (reason?: unknown) => {
this.status = 'rejected'; this.status = 'rejected';
this.stoppedAt = Date.now(); this.stoppedAt = Date.now();
reject(reason); reject(reason);
@@ -49,6 +49,6 @@ export class Deferred<T> {
} }
} }
export const defer = <T>() => { export const defer = <T = void>() => {
return new Deferred<T>(); return new Deferred<T>();
}; };
+4 -4
View File
@@ -5,10 +5,10 @@
"target": "ES2022", "target": "ES2022",
"module": "NodeNext", "module": "NodeNext",
"moduleResolution": "NodeNext", "moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true "verbatimModuleSyntax": true,
"types": ["node"]
}, },
"exclude": [ "exclude": ["dist_*/**/*.d.ts"]
"dist_*/**/*.d.ts"
]
} }