Function meaningPromiseOrThrow

  • Function that generates a "then" function for Promise that avoid any empty data by throwing an error.

    Input:

    • any => any
    • 0 => 0
    • boolean => boolean
    • "" => throw an error
    • null => throw an error
    • undefined => throw an error
    • [] => throw an error
    • {} => throw an error

    Example (es module)

    import { meaningPromiseOrThrow } from '@helpers4/promise'
    Promise.resolve('')
    .then(meaningPromiseOrThrow('My custom error message'))
    .then(console.log)
    // => 'My custom error message'

    Type Parameters

    Type Parameters

    • T

    Parameters

    • error: string

      the error message thrown if the data is null, undefined or empty string

    Returns ((data: T) => T | never)

      • (data: T): T | never
      • Parameters

        • data: T

        Returns T | never

Generated using TypeDoc