Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to understand madge's circular dependency results for an Angular project #395

Open
brianreinhold opened this issue Dec 2, 2023 · 1 comment

Comments

@brianreinhold
Copy link

I am new to madge but very confused by its results. In my project I did the following:

PS E:\projects\Angular\HubView> npx madge --circular --extensions ts ./
Processed 80 files (7.3s) (30 warnings)

✖ Found 3 circular dependencies!

1) src/app/services/api.service.ts > src/app/services/utils.service.ts > src/app/services/exchange.service.ts > src/app/services/aps.service.ts
2) src/app/services/provisioning.service.ts > src/app/services/tree.service.ts
3) src/app/services/tree.service.ts > src/app/services/user.service.ts

Then I went ahead and injected a utils service into a DialogComponent. Now the utils service depends upon nothing, but it does import an interface from another service called exchange. I repeated the test and got

PS E:\projects\Angular\HubView> npx madge --circular --extensions ts ./
Processed 80 files (7.3s) (30 warnings)

✖ Found 5 circular dependencies!

1) src/app/dialog/dialog.component.ts > src/app/services/utils.service.ts
2) src/app/dialog/dialog.component.ts > src/app/services/utils.service.ts > src/app/services/exchange.service.ts
3) src/app/services/utils.service.ts > src/app/services/exchange.service.ts > src/app/services/aps.service.ts > src/app/services/api.service.ts
4) src/app/services/provisioning.service.ts > src/app/services/tree.service.ts
5) src/app/services/tree.service.ts > src/app/services/user.service.ts

My understanding is that importing an interface from a service does not introduce a dependency upon that service. Yes, the DialogCcomponent does depend upon the utils service, but the utils service does not depend upon the DialogComponent or anything else for that matter. The exchange service also does not depend upon any other services but it does import an interface from the aps service. How do I read these results?

Does madge consider the import of an interface a dependency upon the service where that interface is defined?

@soryy708
Copy link

soryy708 commented Dec 6, 2023

Try import type {...} as opposed to import {...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants