Reactjs 将ref用于材质UI输入标签

Reactjs 将ref用于材质UI输入标签,reactjs,typescript,material-ui,Reactjs,Typescript,Material Ui,如何在TypeScript中访问@material ui/core的InputLabel的ref参数 以下代码导致ref出现错误: TS2769:没有与此调用匹配的重载 导出类组合框扩展了React.Component{ 私有inputLabelRef=React.createRef(); 公共渲染(){ 返回 {this.props.caption} this.onChangeSelection(e.target.value)} 标签宽度={200}> {this.renderItems()}

如何在TypeScript中访问
@material ui/core
的InputLabel的
ref
参数

以下代码导致
ref
出现错误:

TS2769:没有与此调用匹配的重载

导出类组合框扩展了React.Component{
私有inputLabelRef=React.createRef();
公共渲染(){
返回
{this.props.caption}
this.onChangeSelection(e.target.value)}
标签宽度={200}>
{this.renderItems()}
;
}
...
}
我已经尝试使用泛型,尝试:

private inputLabelRef = React.createRef<InputLabel>();
private inputLabelRef=React.createRef();
但这会导致
InputLabel
出现以下错误:

“InputLabel”引用了一个值,但在此处用作类型。ts(2749)

正在使用以下版本:

  • “@material ui/core”:“4.6.1”
  • “@types/react”:“16.9.11”
  • “@types/react-dom”:“16.9.4”
  • “反应”:“16.11.0”
  • “react dom”:“16.11.0”
  • “类型脚本”:“3.7.4”

InputLabel中的ref被转发到根元素。因此,您需要使用实际的html元素接口键入它。将其更改为以下内容应可行:

private inputLabelRef=React.createRef();
private inputLabelRef = React.createRef<InputLabel>();