typescript - 如何记录外部 react 组件的类型

标签 typescript

我正在尝试在我的项目中的 global.d.ts 中记录库的类型。

我不知道如何指定默认导出应该是具有这样那样的 Prop 的 react 组件。

我发现有关 ComponentClass 的提及,但没有相关信息。

我想它应该是这样的:

declare module 'yes-exporting-component' {
  const PieChart: <{
    data: { color: string, value: any }[]
  }>;
  export default PieChart;
}

显然上面的语法是不正确的。

最佳答案

你可以尝试这样做:

declare module 'yes-exporting-component'
{
    export interface MyPropType
    {
        data: { color: string, value: any }[];
    }

    class PieChart extends React.Component<MyPropType, any>
    {

    }

    export default PieChart;
}

关于typescript - 如何记录外部 react 组件的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44499753/

相关文章:

javascript - 使用 index.ts 导出 'default'

angular - 如何通过使用私有(private)方法/属性来修改公共(public)方法/属性的输出的依赖项来测试 Angular 6 服务

javascript - 扩展 TypeScript 的控制台界面

typescript - 如何导入外部库并将其转换为 Typescript 中的 <any>?

typescript - 以编程方式访问 TypeScript 调用堆栈

angular - 获取状态码 http.get response angular2

reactjs - typescript 给出类型 '"测试 "' is not assignable to type ' 未定义'

javascript - 当我运行应用程序时,哪个文件首先在 angular 4 应用程序中运行?

typescript - 联合类型允许错误分配所用类型的属性

angular - Typescript 中全局变量的解构赋值