lazarljubenovic/type-guards

Add a general signature for `or` (no guards)

Closed this issue · 0 comments

Today I had an array of functions which were not guards, and I couldn't use tg.fp.or on them, because the signature requires a guard.

export function numberEndsIn (desiredLastDigits: string) {
  return (number: number | string): boolean => {
    const numberString = number.toString()
    return numberString.endsWith(desiredLastDigits)
  }
}

export function numberEndsInOneOf (...desiredLastDigits: string[]) {
  return (tg.fp.or as any)(...desiredLastDigits.map(numberEndsIn))
}

There's no reason not allow usage of these fp helpers, even when no guards are used.