@8hobbies/utils
    Preparing search index...

    Function isOneOf

    • Returns whether array includes element.

      Logically this is the same as array.includes(element), but is typed differently to accommondate the scenario in which array contains literal-type elements. See is-one-of for details.

      Type Parameters

      • T

        The type of element.

      • ArrayElement

      Parameters

      • element: T

        The element to be determined whether it is included in array.

      • array: readonly ArrayElement[]

        The array to be determined whether it includes element.

      Returns element is ArrayElement

      Whether whether array includes element.

    • Returns whether set includes element.

      Logically this is the same as set.has(element), but is typed differently to accommodate the scenario in which set contains literal-type elements. See is-one-of for details.

      Type Parameters

      • T

        The type of element.

      • SetElement

      Parameters

      • element: T

        The element to be determined whether it is included in set.

      • set: Readonly<Set<SetElement>>

        The set to be determined whether it includes element.

      Returns element is SetElement

      Whether whether set includes element.

    • A catch-all overload of the other two overloads. Check out the other two overloads for details.

      This overload addresses the edge case in which collection may be either a Array or Set, and is expected to be used rarely.

      Type Parameters

      • T
      • Element

      Parameters

      Returns element is Element

      for (const collection of [
      ["apple", "orange"] as const,
      new Set(["green", "red"] as const),
      ]) {
      isOneOf("sky", collection);
      // collection is of type readonly ["apple", "orange"] | Set<"green" | "red">
      }