dia-gov's picture
Upload 569 files
cd6f98e verified
raw
history blame
442 Bytes
type Constructor<T> = new (...args: unknown[]) => T;
/* Check whether array is of the specified type */
export const isArrayOfType = <T>(
arr: unknown[] | unknown,
type: Constructor<T> | string
): arr is T[] => {
return (
Array.isArray(arr) &&
arr.every((item): item is T => {
if (typeof type === "string") {
return typeof item === type;
} else {
return item instanceof type;
}
})
);
};