/** @module pairs/toPairs.ts */ import { IsArray, ValueOf } from '../helper-types' import { ObjectTypeProps } from './entries' import { toIterablePair } from './toIterablePair' type ToPairs = { 'array': Array<[string, ValueOf]>; 'object': Array<[string, O[Exclude>]]>; 'iterable': O extends Iterable ? Array<[string, U]> : never; 'iterable2': O extends IterableIterator<[infer U, infer V]> ? Array<[U, V]> : never; 'done': []; }[O extends IterableIterator<[any, any]> ? 'iterable2' : O extends Iterable ? 'iterable' : IsArray] export function toPairs>( obj: A ): Array<[A extends Map ? K : never, A extends Map ? V : never]> export function toPairs>( obj: A ): Array<[string, A[keyof A]]> export function toPairs( obj: A ): Array<[string, A extends Array ? U : never]> /** * Todo */ export function toPairs( obj: A ): A extends { [k in string]: infer V; } ? Array<[string, V]> : never export function toPairs( obj ) { const arr: Array<[any, any]> = [] for ( const r of toIterablePair( obj ) ) { arr.push( r ) } return arr }