return clone<T>(object);
}
- public static isIterable<T extends Iterable<T>>(obj: T): boolean {
+ public static isIterable<T>(obj: T): boolean {
return !Utils.isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
}
expect(Utils.isIterable('test')).toBe(true);
expect(Utils.isIterable(null)).toBe(false);
expect(Utils.isIterable(undefined)).toBe(false);
- expect(Utils.isIterable([])).toBe(true);
+ expect(Utils.isIterable([0, 1])).toBe(true);
+ expect(Utils.isIterable({ 1: 1 })).toBe(false);
+ expect(Utils.isIterable(new Map())).toBe(true);
+ expect(Utils.isIterable(new Set())).toBe(true);
+ expect(Utils.isIterable(new WeakMap())).toBe(false);
+ expect(Utils.isIterable(new WeakSet())).toBe(false);
});
it('Verify isEmptyString()', () => {
return value as T;
}
- public static isIterable<T extends Iterable<T>>(obj: T): boolean {
+ public static isIterable<T>(obj: T): boolean {
if (obj === null || obj === undefined) {
return false;
}
- return typeof obj[Symbol.iterator] === 'function';
+ return typeof (obj as any)[Symbol.iterator] === 'function';
}
// public static ifNotIterableDo<T>(obj: T, cb: () => void): void {