-
Notifications
You must be signed in to change notification settings - Fork 327
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
Madge for typescript: skipping type imports still produces wrong result while searching for circular dependencies #232
Comments
Same for import type syntax: foo.ts import type { Bar } from 'bar'
export type Foo = {
bar: string;
};
export function doFoo() {
return true;
} bar.ts import type { Foo } from 'foo'
export type Bar = {
bar: string;
};
export function doBar() {
return true;
} madge config: {
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
},
"baseDir": "./src",
"fileExtensions": [
"ts"
],
"excludeRegExp": [
"^.*__tests__.*$",
"^.*__mocks__.*$"
],
"tsConfig": "tsconfig.json"
} Output:
|
There's a PR here dependents/detective-typescript#27 by @eelco which looks to add support for |
Could you see if Madge v3.9.0 works for you now @vicrac ? |
@pahen unfortunately, I'm still experiencing the same issue. |
I just had the same issue and figured out the reason. Reasondependents/detective-typescript#27 was released in
Upgrading Madge to v3.9 would install So this means that, if you already have How to solveThere’s probably no library-level solution – unless you convince Locally, I solved this by
This pulled the latest version of precinct dependencies, including Yarn resolutions can also help solving this. |
Thanks for looking into this. I released Madge v3.9.2 now which will hopefully work better since |
Wanna give it a try again @vicrac ? |
@pahen I have similar issues with typescript > 4.0. I have installed madge with version 3.12.0.
|
Working with madge 3.12 and this in package.json:
|
Importing as a type is available since TS 3.8 and allows to import types that are exclusively used for annotations and removed after the build. This additionally changes the Madge configuration to not complain when type imports are used. See pahen/madge#232
I just spent some time debugging this issue, just to find that I had mistyped |
I am still encountering this issue with |
This also doesn't work if you pass it by code: const madge = require('madge');
madge('app/models/index.ts', {
detectiveOptions: {
es6: { skipTypeImports: true }
}
}).then((res) => {
console.log(res.circular());
}); Still returns circular type imports |
Back again... this time I needed to add a "tsx" block to the {
"detectiveOptions": {
"ts": {
"skipTypeImports": true
},
"tsx": {
"skipTypeImports": true
}
}
} |
work if we add type : ex |
es6 + ts config works for my typescript project |
This seems to be the case 😕 Unfortunately I'm working on a huge existing React project, and we often import types along with values like this: import { Component, ComponentProps } from "./Component" Because of this, our dependency graphs are extremely messy (together with poor dependency flow), and it would be very tedious to manually re-write all type imports into @pahen , @realityking do you think it would be feasible to distinguish types and interfaces on the fly, regardless of import syntax? I'm willing to contribute, but unsure if it's worth even digging in :) I think it would at the very least make sense to document this in README. |
v6 solved my issues, thank you very much 🙏 |
Are you sure? Still not working for me. I have to specify |
Yes, I am - I'm sad to hear that isn't working for you. Try with this config, this is what I am using:
|
Not sure if it's better to comment here or on #340, but I've found that the specific type syntax matters: import { type TheType } from './types'; // is INCLUDED when `skipTypeImports: true` import type { TheType } from './types'; // is EXCLUDED when `skipTypeImports: true` I have also tried both syntaxes with the config provided above (#232 (comment)). Only when the using {
"detectiveOptions": {
"ts": {
"skipTypeImports": true
},
"tsx": {
"skipTypeImports": true
}
}
} For reference, I'm invoking madge using only a small portion of my project, and with command similar to: pnpm dlx madge --include-npm src/pages/Page1/index.tsx --debug |
Post TS 5.0, I'd argue that requiring the
For help fixing the issues, see |
I have
moduleA.ts
and
moduleB.ts
:Following advice from @pahen (see (#231)) I enabled skipping type imports in typescript (since cyclic deps are allowed in this case), so I added to my
.madgerc
file in root directory:but I'm still getting error:
Is there something I am missing, or is it a bug?
The text was updated successfully, but these errors were encountered: