@js-bits/xpromise
Advanced tools
Comparing version 1.0.14 to 1.0.15
@@ -1,12 +0,3 @@ | ||
export default ExtendablePromise; | ||
export type Resolve<T> = (value: T | PromiseLike<T>, ...rest: unknown[]) => void; | ||
export type Reject = (reason?: Error) => void; | ||
export = ExtendablePromise; | ||
/** | ||
* @template T | ||
* @typedef {(value: T | PromiseLike<T>, ...rest:unknown[]) => void} Resolve | ||
*/ | ||
/** | ||
* @typedef {(reason?: Error) => void} Reject | ||
*/ | ||
/** | ||
* Allows extension of JavaScript's standard, built-in `Promise` class. | ||
@@ -20,6 +11,6 @@ * Decouples an asynchronous operation that ties an outcome to a promise from the constructor. | ||
* Creates new `ExtendablePromise` instance. | ||
* @param {(resolve:Resolve<T>, reject:Reject, ...rest:unknown[]) => void} executor - A function to be executed by the `.execute()` method | ||
* @param {import('./types').ExecutorFunc<T>} executor - A function to be executed by the `.execute()` method | ||
* @throws {typeof ExtendablePromise.InstantiationError} | ||
*/ | ||
constructor(executor: (resolve: Resolve<T>, reject: Reject, ...rest: unknown[]) => void); | ||
constructor(executor: import('./types').ExecutorFunc<T>); | ||
/** | ||
@@ -47,8 +38,9 @@ * Executes `executor` function provided to `ExtendablePromise` constructor. | ||
*/ | ||
readonly [UniqueSymbols.UNIQUE_SYMBOL493]: Resolve<T>; | ||
readonly [UniqueSymbols.UNIQUE_SYMBOL493]: import("./types").Resolve<T>; | ||
/** | ||
* @readonly | ||
*/ | ||
readonly [UniqueSymbols.UNIQUE_SYMBOL494]: Reject; | ||
[UniqueSymbols.UNIQUE_SYMBOL492]: (resolve: Resolve<T>, reject: Reject, ...rest: unknown[]) => void; | ||
readonly [UniqueSymbols.UNIQUE_SYMBOL494]: import("./types").Reject; | ||
/** @type {import('./types').ExecutorFunc<T> | undefined} */ | ||
[UniqueSymbols.UNIQUE_SYMBOL492]: import('./types').ExecutorFunc<T> | undefined; | ||
} | ||
@@ -55,0 +47,0 @@ declare namespace ExtendablePromise { |
24
index.js
@@ -12,11 +12,2 @@ import enumerate from '@js-bits/enumerate'; | ||
/** | ||
* @template T | ||
* @typedef {(value: T | PromiseLike<T>, ...rest:unknown[]) => void} Resolve | ||
*/ | ||
/** | ||
* @typedef {(reason?: Error) => void} Reject | ||
*/ | ||
/** | ||
* Allows extension of JavaScript's standard, built-in `Promise` class. | ||
@@ -30,9 +21,9 @@ * Decouples an asynchronous operation that ties an outcome to a promise from the constructor. | ||
* Creates new `ExtendablePromise` instance. | ||
* @param {(resolve:Resolve<T>, reject:Reject, ...rest:unknown[]) => void} executor - A function to be executed by the `.execute()` method | ||
* @param {import('./types').ExecutorFunc<T>} executor - A function to be executed by the `.execute()` method | ||
* @throws {typeof ExtendablePromise.InstantiationError} | ||
*/ | ||
constructor(executor) { | ||
/** @type {Resolve<T>} */ | ||
/** @type {import('./types').Resolve<T>} */ | ||
let resolve; | ||
/** @type {Reject} */ | ||
/** @type {import('./types').Reject} */ | ||
let reject; | ||
@@ -47,2 +38,3 @@ super((res, rej) => { | ||
*/ | ||
// @ts-expect-error ts(2454) | ||
this[ø.resolve] = resolve; | ||
@@ -53,5 +45,7 @@ | ||
*/ | ||
// @ts-expect-error ts(2454) | ||
this[ø.reject] = reject; | ||
if (typeof executor === 'function') { | ||
/** @type {import('./types').ExecutorFunc<T> | undefined} */ | ||
this[ø.executor] = executor; | ||
@@ -80,3 +74,7 @@ } else { | ||
try { | ||
this[ø.executor](this.resolve.bind(this), this.reject.bind(this), ...args); | ||
/** @type {import('./types').ExecutorFunc<T>} */ (this[ø.executor])( | ||
this.resolve.bind(this), | ||
this.reject.bind(this), | ||
...args | ||
); | ||
} catch (cause) { | ||
@@ -83,0 +81,0 @@ const error = new Error('Promise execution failed. See "cause" property for details'); |
@@ -36,4 +36,6 @@ /* eslint-disable max-classes-per-file, import/no-extraneous-dependencies, no-unused-vars */ | ||
expect.assertions(4); | ||
// @ts-ignore | ||
promise = undefined; | ||
try { | ||
// @ts-expect-error ts(2345) | ||
promise = new ExtendablePromise(null); | ||
@@ -51,2 +53,3 @@ } catch (error) { | ||
expect.assertions(3); | ||
// @ts-ignore | ||
promise = undefined; | ||
@@ -77,5 +80,7 @@ try { | ||
} | ||
// @ts-ignore | ||
promise = undefined; | ||
let result = 'unchanged'; | ||
try { | ||
// @ts-ignore | ||
promise = new MyPromise(); | ||
@@ -102,3 +107,5 @@ result = /** @type {string} */ (await promise); | ||
} | ||
// @ts-ignore | ||
promise = undefined; | ||
// @ts-ignore | ||
promise = new MyPromise(); | ||
@@ -253,2 +260,3 @@ const result = await promise; | ||
}); | ||
// @ts-ignore | ||
reject('error'); | ||
@@ -255,0 +263,0 @@ let result; |
{ | ||
"name": "@js-bits/xpromise", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"description": "Extendable Promise", | ||
@@ -24,4 +24,5 @@ "keywords": [ | ||
"scripts": { | ||
"build": "rimraf ./dist && yarn build:dts && rollup ./index.js --format cjs --file dist/index.cjs --exports default", | ||
"build:dts": "tsc ./index.js --allowJs --emitDeclarationOnly --declaration --outDir dist && yarn replace:symbols ./dist/index.d.ts", | ||
"build": "rimraf ./dist && yarn build:dts && rollup ./index.js --format cjs --file dist/index.cjs --exports default --no-strict --generatedCode.constBindings", | ||
"build:dts": "tsc ./index.js --allowJs --emitDeclarationOnly --declaration --esModuleInterop --outDir dist && yarn replace:symbols ./dist/index.d.ts && yarn prepare:dts", | ||
"prepare:dts": "node ./node_modules/@js-bits/typedef-utils/scripts/prepare-dts.js ./dist/index.d.ts", | ||
"replace:symbols": "node node_modules/@js-bits/enumerate/scripts/replace-unique-symbols", | ||
@@ -41,3 +42,3 @@ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --verbose", | ||
"dependencies": { | ||
"@js-bits/enumerate": "^1.0.17" | ||
"@js-bits/enumerate": "^1.0.19" | ||
}, | ||
@@ -44,0 +45,0 @@ "devDependencies": { |
@@ -10,2 +10,5 @@ { | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"types": ["jest"], | ||
@@ -12,0 +15,0 @@ "typeRoots": ["./node_modules/@types"], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28690
16
735
Updated@js-bits/enumerate@^1.0.19