Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 财产';参考';不存在于类型';A';。ts(2339)-反应,打字脚本_Javascript_Reactjs_Typescript - Fatal编程技术网

Javascript 财产';参考';不存在于类型';A';。ts(2339)-反应,打字脚本

Javascript 财产';参考';不存在于类型';A';。ts(2339)-反应,打字脚本,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,错误: 类型“A”上不存在属性“ref”。ts(2339) 这是我的源代码 export default class A extends React.PureComponent<Props, State> { constructor(props: Props) { super(props); this.ref = React.createRef(); << ERROR HERE 导出默认类A扩展React.PureComponent{ 建造师(道具

错误:

类型“A”上不存在属性“ref”。ts(2339)

这是我的源代码

export default class A extends React.PureComponent<Props, State> {
  constructor(props: Props) {
    super(props);

    this.ref = React.createRef(); << ERROR HERE
导出默认类A扩展React.PureComponent{
建造师(道具:道具){
超级(道具);

this.ref=React.createRef();必须在类主体中声明
ref
变量

export default class A extends React.PureComponent<Props, State> {
   ref: React.RefObject<HTMLInputElement>;

   constructor(props: Props) {
      super(props);

      this.ref = React.createRef();
   }
}
导出默认类A扩展React.PureComponent{
ref:React.reObject;
建造师(道具:道具){
超级(道具);
this.ref=React.createRef();
}
}
或者基本上移除构造函数并将逻辑移到外部

export default class A extends React.PureComponent<Props, State> {
  ref = React.createRef();
导出默认类A扩展React.PureComponent{
ref=React.createRef();

谢谢善良的用户。
ref的类型是什么?
ref;
@hellofengineer上的另一个问题是ref的类型是它所指的组件。
React.createRef();
你很善良:D