我有一个React项目正在其他多个项目之间使用。我正在切换到打字稿,现在我的其他项目中缺少打字稿定义。为了解决这个问题,我定义了一个带有通用接口的index.d.ts文件,但我想使用每个react组件都具有的接口进行扩展。
// index.d.ts
export interface CommonProps {
id: string;
children: any;
}
我已经链接了package.json中的类型定义
// package.json
...
"types": "./index.d.ts"
有没有一种方法可以使用在组件内部定义的接口来扩展index.d.ts文件。我的项目结构就像src/components/text/text.tsx
,在text.tsx
内部,我有
interface TextProps extends CommonProps { ... }
之所以这样做,是因为我想在使用Text组件的其他项目中使用TextProps。