I encountered below code snippets which contain a cyclic importing dependency on type reference.
// Foo.ts
import { Bar } from './Bar';
export interface Foo {
isBarOK: (bar: Bar) => boolean;
}
// Bar.ts
import { Foo } form './Foo';
export class Bar {
protected readonly foo: Foo;
}
This is a simplified version but it explains the case I encountered. tsc
has no problem in compiling the code, but I got a warning from the import/no-cycle ESLint rule. We can see that Foo
and Bar
references each other for typing. Is this a bad practice? What impacts does it imply?