pahen / madge

Create graphs from your CommonJS, AMD or ES6 module dependencies
MIT License
9.09k stars 318 forks source link

Typescript skipTypeImports and merged declarations #233

Open ziriax opened 4 years ago

ziriax commented 4 years ago

We use the following pattern a lot in our Typescript code:

export interface Person { ... };

export const Person = { ...};

The Typescript compiler wants these to be in the same file.

(Originally we used namespaces for this, but babel doesn't support these fully yet, and the same problem would exist if it it)

When importing the person module and using only the Person type, so not the Person object variable, madge still considers this as a cyclic dependency, even though the resulting Javascript code doesn't have any cycles anymore (as far as know).

The Typescript compiler has no problems with these cyclic type imports.

This seems pretty hard to solve, but reporting it anyway...

PabloLION commented 1 year ago

This seems an anti-pattern yet it's accepted by TS engine. We should try to resolve this.

ollwenjones commented 1 year ago

Similar: Noticed we had a lot of false-positives for cycles running madge where only a TS Interface is imported as well. Our are usually export interface ITypeOfThing {...} along side an export of a concrete thing, e.g. a React component props interface, alongside a component definition. We don't have the problem with the names being identical, but madge still didn't seem to differentiate a types-only import from a real-code import.

EchoZhaoH commented 1 month ago

any updates?