madge: Madge for typescript: skipping type imports still produces wrong result while searching for circular dependencies
I have
moduleA.ts
import * as Life from './moduleB';
export interface Person {
age: number;
health: number;
// ...
}
export const live = (p: Person) => Life.goToDoctor(Life.getOld(p))
console.log(live({
age: 65,
health: 0.6,
}))
and moduleB.ts:
import { Person } from './moduleA'
export const getOld = (p: Person): Person => ({
...p,
age: p.age + 1
})
export const goToDoctor = (p: Person): Person => ({
...p,
health: Math.min(p.health * 1.2, 1)
})
Following advice from @pahen (see (https://github.com/pahen/madge/issues/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:
{
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
}
}
but I’m still getting error:
Processed 2 files (584ms)
✖ Found 1 circular dependency!
1) moduleA.ts > moduleB.ts
Is there something I am missing, or is it a bug?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 17
- Comments: 22 (4 by maintainers)
Same for import type syntax:
foo.ts
bar.ts
madge config:
Output:
Back again… this time I needed to add a “tsx” block to the
.madgerc:Not sure if it’s better to comment here or on #340, but I’ve found that the specific type syntax matters:
I have also tried both syntaxes with the config provided above (https://github.com/pahen/madge/issues/232#issuecomment-1602761190). Only when the using
import type { ...}did the following minimum options work for my TS/TSX project:For reference, I’m invoking madge using only a small portion of my project, and with command similar to:
i can also confirm something wrong !
"madge": "^3.12.0",usingskipTypeImportsnot workActually the test look like thats index.jsx
1.tsx
2.tsx
2.tsx should not considerate because import only type.
It seems like a dup of #330, could you confirm please @kamiazya ?
work if we add type : ex
import type { } from ".../";I am still encountering this issue with
madge v5.0.1. Madge behaves as if the configurationskipTypeImports: truedoesn’t exist withtypescript v4.4.2. Any advice would be greatly appreciated.