Javascript TypeScript在多个文件中导入的类型定义中断应用程序

Javascript TypeScript在多个文件中导入的类型定义中断应用程序,javascript,node.js,typescript,types,enums,Javascript,Node.js,Typescript,Types,Enums,我在其他文件中使用类型定义文件时遇到问题 我有以下文件夹结构: |_ foo | |_ service.ts | |_ schema.ts | |_ index.ts | |_ types.d.ts |_ index.ts 这是我的类型。d.ts: export enum EBar { a = 'a', b = 'b' } export interface IBaz { id: number, title: string } export interface IData

我在其他文件中使用类型定义文件时遇到问题

我有以下文件夹结构:

|_ foo
| |_ service.ts
| |_ schema.ts
| |_ index.ts 
|
|_ types.d.ts
|_ index.ts
这是我的
类型。d.ts

export enum EBar {
  a = 'a',
  b = 'b'
}

export interface IBaz {
  id: number,
  title: string
}

export interface IData {
  bar: EBar;
  baz: IBaz[];
}
service.ts内部
我正在使用类型:

import { EBar, IBaz, IData } from '../types';

// ...functions and methods that utilize these types...
同样在
schema.ts中,我从类型派生:

import Joi from '@hapi/joi';

import { EBar } from '../types';

const BAR_A = EBar.a;
const BAR_B = EBar.b;

export default const schema = Joi.object().keys({
  bar: Joi.string().valid(BAR_A, BAR_B),
  baz: Joi.array().items()
});
架构和服务都导入到
foo/index.ts
文件中:

import { methodA, methodB, methodC } from './service';
import schema from './schema';

// ...use methods and schema
但是,在运行应用程序时,我总是遇到以下错误:

[Node] Provided module can't be loaded.
[Node] Did you list all required modules in the package.json dependencies?
[Node] Detailed stack trace: Error: Cannot find module '../types'
但是当我删除
EBar
scheme.ts中的用法时,错误就会消失

有没有人经历过类似的事情


Repo with repeatable demo-

看起来您遇到了循环依赖性问题。我也考虑过这一点,并用于分析循环依赖性的代码,得到了
✔ 没有找到循环依赖项但即使它是循环的,那也很棘手,我如何组织代码,以在多个文件中重用类型的方式?!看起来很奇怪。你是直接使用tsc还是像webpack或parcel这样的东西?@ClémentBerthou我创建了github repo,这个问题-看起来你有一个循环依赖性问题。我也考虑过这个问题,并用它来分析循环依赖性的代码,得到了
✔ 没有找到循环依赖项但即使它是循环的,那也很棘手,我如何组织代码,以在多个文件中重用类型的方式?!看起来很奇怪。你是直接使用tsc还是类似于网页包或包裹的东西?@ClémentBerthou我用这个问题创建了github repo-