import { IAsyncEnumerable } from "../../types/IAsyncEnumerable" ; import { InferType , OfType } from "../../types/InferType" ; import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable" ; param source param type returns export const ofType = < TSource , TType extends OfType > ( source , type ) : IAsyncEnumerable < InferType < TType > > => { const typeCheck = typeof type === "string" ? ( ( x ) => typeof x === type ) as ( x : TSource ) => x is InferType < TType > : ( ( x ) => x instanceof ( type as any ) ) as ( x : TSource ) => x is InferType < TType > ; async function * iterator ( ) { for await ( const item of source ) { if ( typeCheck ( item ) ) { yield item ; } } } return new BasicAsyncEnumerable ( iterator ) ; } ;