admin管理员组文章数量:1431918
Error:
Property 'ref' does not exist on type 'A'.ts(2339)
Here is my source code
export default class A extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.ref = React.createRef(); << ERROR HERE
How can I define type of A
to resolve the error?
Error:
Property 'ref' does not exist on type 'A'.ts(2339)
Here is my source code
export default class A extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.ref = React.createRef(); << ERROR HERE
How can I define type of A
to resolve the error?
1 Answer
Reset to default 7You have to declare the ref
variable in the class body.
export default class A extends React.PureComponent<Props, State> {
ref: React.RefObject<HTMLInputElement>;
constructor(props: Props) {
super(props);
this.ref = React.createRef();
}
}
or basically remove the constructor and move logic outside.
export default class A extends React.PureComponent<Props, State> {
ref = React.createRef();
本文标签: javascriptProperty 39ref39 does not exist on type 39A39ts(2339)ReacttypescriptStack Overflow
版权声明:本文标题:javascript - Property 'ref' does not exist on type 'A'.ts(2339) - React, TypeScript - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744908103a2631744.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论