benawad / destiny

Prettier for File Structures
MIT License
3.53k stars 80 forks source link

Dependency cycle with TypeScript types #124

Open jdeniau opened 4 years ago

jdeniau commented 4 years ago

Hi,

thanks for developing destiny. It looks really interesting.

I noticed #123 and all linked issues, but I prefer opening a new issue, even if it can be related.

Imagine the two following files:

main.ts

import foo from './foo';

export type MAIN = string | number;

function main(key: MAIN): void {
  foo(key);
}

foo.ts

import type { MAIN } from './main';

export default function foo(key: MAIN): void {
  console.log(key);
}

Running destiny, I got the following warning:

 Dependency cycle detected: foo.ts -> main.ts -> foo.ts

And with bigger codebase, I think it it responsible for not having the shared folder, but a list of nested directory: image

I think the types definition may be omitted for typescript.

In the first example, the resulting structure may be

main/
|- index.ts
|- index/
|-- foo.ts

(or something like that 😉 )

AnatoleLucet commented 4 years ago

Hi! I have some trouble understanding what's the issue here. Can you please describe what Destiny currently do with your example and what you expect it to do?