I'm running into a circular dependency detected warning in an Angular app using individually exported functions from two utility files. I'll show a simplified example of the two files below.
The first file:
// type-helper.ts
import {getPropertyIfExists} from "./helper";
export function isType(item: any, type: string, property?: string) {
const target = getPropertyIfExists(item, property);
if (typeof type !== "string") return false;
else return typeof target === type;
}
export function isArray(item: any[] | any): item is any[] {
return item && Array.isArray(item);
}
export function isObject(item: object | any): item is object {
return item && typeof item === 'object';
}
The second file:
// helper.ts
import {isArray, isObject} from "./type-helper";
export function getPropertyIfExists(item: any, property?: string): any {
if (property) return item[property];
else return item;
}
export function removeUndefinedProperties<T>(obj: T): T {
const keys = Object.keys(obj);
for (const key of keys) {
if (isArray(obj[key])) obj[key] = removeEmptyValuesFromArray(obj[key]);
else if (isObject(obj[key])) obj[key] = removeUndefinedProperties(obj[key]);
else if (item === undefined || item === null) delete obj[key];
}
return obj;
}
Both of these files provide small utilities that I like reusing in my application without necessarily being linked to a single service. As far as I can tell, there are no other links between these files.
So, my questions:
- Is the warning expected behaviour? I understand the warning if you have circular dependencies between components and services, where the entire class is imported, but in this case there is no circular dependency between the items actually being imported.
- If it's not a problem, is there a way to make the warning disappear for this specific situation (without removing the warning from other circular dependencies)?
Thanks!