@mirei/ts-collections
    Preparing search index...

    Function ofType

    • Filters the sequence, keeping only elements assignable to the specified type.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TResult extends ObjectType

        Type descriptor used to filter elements (constructor function or primitive type string).

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • type: TResult

        Type descriptor that determines which elements are retained (e.g., 'string', Number, Date).

      Returns IEnumerable<InferredType<TResult>>

      A sequence containing only the elements that match the specified type.

      This function performs a runtime type check for each element and yields matching elements lazily.

      const mixed = [1, 'two', 3, 'four', new Date()];
      const numbers = ofType(mixed, 'number').toArray();
      console.log(numbers); // [1, 3]

      const dates = ofType(mixed, Date).toArray();
      console.log(dates); // [Date object]