I just had this issue with a simple component and directive inside a library.
The directive injects the component, and the component uses this directive in the template. So a typescript import cycle is introduced.
resizable.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'lib-resizable',
template: `<div [resizableGlyph]="['top', 'start']"></div>`
})
export class ResizableComponent {}
resizable-glyph.directive.ts
import { Directive, Input } from '@angular/core';
import { ResizableComponent } from '../resizable/resizable.component';
export type Position = 'top' | 'end' | 'bottom' | 'start';
@Directive({ selector: '[resizableGlyph]' })
export class ResizableGlyphDirective {
constructor(private resizable: ResizableComponent) { }
@Input('resizableGlyph') positions: Position[] = [];
}
To solve this, I had to use import type
resizable.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'lib-resizable',
template: `<div [resizableGlyph]="['top', 'start']"></div>`,
providers: [
{ provide: 'RESIZABLE', useExisting: ResizableComponent }
]
})
export class ResizableComponent {}
resizable-glyph.directive.ts
import { Directive, Inject, Input } from '@angular/core';
// Below solves the import cycle
import type { ResizableComponent } from '../resizable/resizable.component';
export type Position = 'top' | 'end' | 'bottom' | 'start';
@Directive({ selector: '[resizableGlyph]' })
export class ResizableGlyphDirective {
constructor(@Inject('RESIZABLE') private resizable: ResizableComponent) { }
@Input('resizableGlyph') positions: Position[] = [];
}
Commit reference
Now you'll have problems running your jest unit tests. To solve this you need to do the following