Fake Mirrors
    Preparing search index...

    Function arrayIncludes

    • Check array includes a value, type-safe version.

      This function provides a type-guard version of Array.includes that properly narrows the type of the element after checking.

      Type Parameters

      • T
      • U

      Parameters

      • coll: readonly T[]

        The collection to search in

      • el: U

        The element to check for

      Returns el is T

      Type guard indicating if the element is in the collection

      const colors = ['red', 'green', 'blue'] as const
      const value = 'red'

      if (arrayIncludes(colors, value)) {
      // value is now typed as 'red' | 'green' | 'blue'
      console.log(value)
      }