UNPKG

@scayle/storefront-nuxt

Version:

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

34 lines (33 loc) 1.6 kB
/** * Extends a Promise and its resolved value with properties from a source object. * * This effectively allows to treat a Promise as a regular object and * extend it with custom properties, while maintaining its asynchronous behavior. * These added properties are then available on the Promise itself as well as on its resolved value. * * @template T The type of the `Promise` and its resolved value. This should be an object type. * @template U The type of the source object. * * @param promise The original Promise. The Promise's resolved value must have the same interface as the Promise itself. * @param source The source object to merge with the Promise and its resolved value. * * @returns A new Promise with the properties of both the original Promise and the `source` object. * The resolved value of the new Promise also includes the merged properties. * * @example * ```typescript * const originalPromise = Promise.resolve({ initial: 'value' }) as { initial: string } & Promise<{ initial: string }> * const sourceObject = { added: 'objectProperty' } * const extendedPromise = extendPromise(originalPromise, sourceObject) * * // Access `added` property directly on the Promise: * console.log(extendedPromise.added) // 'objectProperty' * * extendedPromise.then(result => { * // Access added property on the resolved value: * console.log(result.initial) // 'value' * console.log(result.added) // 'objectProperty' * }) * ``` */ export declare function extendPromise<T extends object, U>(promise: T & Promise<T>, source: U): T & U & Promise<T & U>;