У меня есть код, в котором eslint выдал ошибку типа: import/no-cycle, но я не понимаю, откуда взялась эта циклическая зависимость.
Точная ошибка: ESLint: Dependency cycle via ../types:7=>./Jobs:1(import/no-cycle).
Файл 1. Вакансии / Вакансии
import { AuthJobs } from './Auth';
export interface IJobs {
auth: AuthJobs;
// ... more types
}
Файл 2. вакансии / типы
import { IJobs } from './Jobs';
// This class doesn't use IJobs
export interface JobRunResponse<D, F = undefined> {
data?: any;
dataError?: JobErrorResponse<D>;
}
Файл 3. jobs / Auth / AuthJobs
// Remember that in File 2, `JobRunResponse` doesn't use `IJobs`
// which at the same time is the one that uses `AuthJobs`
import { JobRunResponse } from '../types';
export class AuthJobs {
// Class properties and methods
}
Файл 4. jobs / Auth / index
// Here is where eslint thown the error
export { AuthJobs } from './AuthJobs';
Структура папки
jobs
├── Auth
│ ├── AuthJobs.ts
│ └── index.ts
├── Jobs.ts
└── types.ts
Пытаясь понять, откуда берется циклическая зависимость, я могу подумать, что когда JobRunResponse из ../types это импортировано в Файл 3(jobs / Auth / AuthJobs), неявно импортировать IJobs это использование AuthJobs, но это не имеет смысла, другого объяснения я найти не могу.
jobs/Jobs -> jobs/Auth/AuthJobs -> jobs/Auth/index -> jobs/Jobs
