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

    Function cast

    • Reinterprets each element in the sequence as the specified result type.

      Type Parameters

      • TResult

        Target type exposed by the returned sequence.

      • TElement = unknown

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      Returns IEnumerable<TResult>

      A sequence that yields the same elements typed as TResult.

      No runtime conversion occurs; ensure the underlying elements are compatible with TResult to avoid downstream failures.

      const mixed = [1, 'two', 3, 'four'];
      const numbers = cast<number>(mixed).where(x => typeof x === 'number');
      console.log(numbers.toArray()); // [1, 3]