【发布时间】:2020-08-17 06:15:08
【问题描述】:
我有 React 和 TypeScript 项目。 这是我在某些组件中的文件夹结构,例如:
- ComponentFolder
- index.tsx
- types.d.ts
- ChildComponent
- index.tsx
我知道如果我将我的类型放在组件目录根目录下的 types.d.ts 文件中,我可以在该目录的 childComponents 中使用这些类型。
所以我尝试了;
我的 types.d.ts 文件:
export type CommonProps = {
openItem: string;
getValue: (e: React.MouseEvent) => void;
};
在子组件中:
import * as React from "react";
const ChildComponent: React.FC<CommonProps> = (props) => {
return (
<div>
{props.openItem}
</div>
);
};
export default ChildComponent;
但出现错误:
cannot find CommonProps error.
我如何知道目录中是否有一些文件 d.ts 我可以在此目录中使用这些类型而无需导入。
我在哪里弄错了?
【问题讨论】:
标签: reactjs typescript