diff --git a/promise.js b/promise.js index c1a0b72..8254fc8 100644 --- a/promise.js +++ b/promise.js @@ -27,11 +27,12 @@ export const createEmpty = f => new Promise(f) /** * `Promise.all` wait for all promises in the array to resolve and return the result - * @template T - * @param {Array>} arrp - * @return {Promise>} + * @template {unknown[] | []} PS + * + * @param {PS} ps + * @return {Promise<{ -readonly [P in keyof PS]: Awaited }>} */ -export const all = arrp => Promise.all(arrp) +export const all = Promise.all.bind(Promise) /** * @param {Error} [reason] diff --git a/promise.test.js b/promise.test.js index 66212b5..4aebb6b 100644 --- a/promise.test.js +++ b/promise.test.js @@ -25,9 +25,9 @@ const measureP = (p, min, max) => { const failsP = p => promise.create((resolve, reject) => p.then(() => reject(error.create('Promise should fail')), resolve)) /** - * @param {t.TestCase} tc + * @param {t.TestCase} _tc */ -export const testRepeatPromise = async tc => { +export const testRepeatPromise = async _tc => { t.assert(promise.createEmpty(r => r()).constructor === Promise, 'p.create() creates a Promise') t.assert(promise.resolve().constructor === Promise, 'p.reject() creates a Promise') const rejectedP = promise.reject() @@ -44,9 +44,9 @@ export const testRepeatPromise = async tc => { } /** - * @param {t.TestCase} tc + * @param {t.TestCase} _tc */ -export const testispromise = tc => { +export const testispromise = _tc => { t.assert(promise.isPromise(new Promise(() => {}))) t.assert(promise.isPromise(promise.create(() => {}))) const rej = promise.reject() @@ -58,3 +58,19 @@ export const testispromise = tc => { t.assert(promise.isPromise({ then: () => {}, catch: () => {} })) }) } + +/** + * @param {t.TestCase} _tc + */ +export const testTypings = async _tc => { + const ps = await promise.all([promise.resolveWith(4), 'string']) + /** + * @type {number} + */ + const a = ps[0] + /** + * @type {string} + */ + const b = ps[1] + t.assert(typeof a === 'number' && typeof b === 'string') +}