• Type guard that checks if a PromiseSettledResult was fulfilled successfully

    Type Parameters

    • T

    Parameters

    • item: PromiseSettledResult<T>

      A PromiseSettledResult to check

    Returns item is PromiseFulfilledResult<T>

    A type predicate indicating if the promise was fulfilled

    const promises = await Promise.allSettled([
    Promise.resolve(1),
    Promise.reject('error')
    ]);

    // Filter to get only successful results with type safety
    const fulfilled = promises.filter(assertFulfilled);
    // fulfilled is now PromiseFulfilledResult<number>[]

    // Access the values safely
    const values = fulfilled.map(result => result.value);

    This is a TypeScript type guard that helps narrow down the type of a PromiseSettledResult to PromiseFulfilledResult. It's particularly useful when working with Promise.allSettled() and you need to filter out rejected promises while maintaining type safety.