Javascript 财产';参考';不存在于类型';A';。ts(2339)-反应,打字脚本
错误: 类型“A”上不存在属性“ref”。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{ 建造师(道具
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