Javascript typescript:在手写类型声明文件中使用三斜杠指令

Javascript typescript:在手写类型声明文件中使用三斜杠指令,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,我有一个用javascript编写的包,我想公开类型定义,以便该包可以适当地用于typescript项目,以及IDE支持typescript的其他javascript项目。目前,我正在手动编写类型定义(同时,我正在寻找使用jsdocs或类似工具为Javscript包自动生成声明文件的方法)。根据当前的支持,我需要一个包的类型定义文件,我可以在package.json中的types属性中引用该文件。由于包相当大并且有许多子文件夹,我决定在每个子文件夹中本地保留一个类型定义文件,并通过顶级index

我有一个用javascript编写的包,我想公开类型定义,以便该包可以适当地用于typescript项目,以及IDE支持typescript的其他javascript项目。目前,我正在手动编写类型定义(同时,我正在寻找使用jsdocs或类似工具为Javscript包自动生成声明文件的方法)。根据当前的支持,我需要一个包的类型定义文件,我可以在
package.json
中的
types
属性中引用该文件。由于包相当大并且有许多子文件夹,我决定在每个子文件夹中本地保留一个类型定义文件,并通过顶级
index.d.ts
将其公开。为此,我在定义接口的地方保留了一个本地
index.d.ts
,然后引用顶级
index.d.ts

包装/组件A/index.d.ts

interface ComponentAProps {
  ...
}
interface ComponentBProps {
  ...
}
/// <reference types="./componentA" />
/// <reference types="./componentB" />

const ComponentA: React.FC<ComponentAProps>;
const ComponentB: React.FC<ComponentBProps>;

export { ComponentA, ComponentB };
包装/组件B/index.d.ts

interface ComponentAProps {
  ...
}
interface ComponentBProps {
  ...
}
/// <reference types="./componentA" />
/// <reference types="./componentB" />

const ComponentA: React.FC<ComponentAProps>;
const ComponentB: React.FC<ComponentBProps>;

export { ComponentA, ComponentB };
包装/索引d.ts

interface ComponentAProps {
  ...
}
interface ComponentBProps {
  ...
}
/// <reference types="./componentA" />
/// <reference types="./componentB" />

const ComponentA: React.FC<ComponentAProps>;
const ComponentB: React.FC<ComponentBProps>;

export { ComponentA, ComponentB };
请注意
include
中的
skipLibCheck:false
*.ts
。这导致声明文件被正确lint,但现在我得到一个与reference指令相关的错误:

Already included file name '/Users/.../ComponentA/index.d.ts' differs from file name '/Users/.../ComponentA/index.d.ts' only in casing.
  The file is in the program because:
    Type library referenced via './componenta' from file '/Users/.../componenta/index.d.ts'
    Matched by include pattern '**/*.ts' in '/Users/.../tsconfig.json'ts(1261)
tsconfig.json(28, 15): File is matched by include pattern specified here.

从这个错误中我可以理解,由于
tsconfig
include模式,
ComponentA/index.d.ts
似乎已经包含了
tsconfig
include模式,通过在顶级
index.d.ts
中引用它,我只是在编译路径中再次包含它。现在我明白这是一个潜在的问题,但我真的不知道如何解决这个问题。我无法删除引用,因为这样类型将显示为
any
。我无法从include path中删除d.ts文件,因为这是首先启用linting的原因。

另一个观察结果:如果我将引用类型替换为引用路径的确切文件名,它似乎可以正常工作