JSX 元素类型 'xxx' 不是 JSX 元素的构造函数。属性 'yyy' 在类型 'xxx' 中受保护,但在类型 'ElementClass' 中是公共的

IT技术 reactjs typescript
2021-05-16 00:37:08

我正在尝试导入Vega-Lite从名为Voyager.

这是我的代码:

import * as React from 'react';
import {VegaLite} from 'datavoyager/build/components/vega-lite';

export interface Props {
  spec: any;
  logger: any;
}

export const View = ({spec, logger}: Props) => {
  return(
    <VegaLite spec={spec} logger={logger}/>
  );
};

这是我的错误:

[ts] JSX 元素类型“VegaLite”不是 JSX 元素的构造函数。属性“componentDidMount”在“VegaLite”类型中受保护,但在“ElementClass”类型中公共。

我知道在课堂上Vega-Lite,功能componentDidMount()确实是protected. 但是我该如何解决这个错误呢?

PS:我试过在我的 中设置allowSyntheticDefaultImports,但同样的错误仍然存​​在。truetsconfig.json

1个回答

您需要将您的react类型降级到以下15.0.25版本。15.0.25版本开始,所有生命周期方法都被强制公开。

这是一个关于它的问题:https : //github.com/DefinitelyTyped/DefinitelyTyped/issues/16893

更好的解决方案是在voyagerrepo 中创建一个问题,它会告诉他们他们的组件与较新的 react 类型不兼容。他们使用^15.0.8.