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();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744908103a4600378.html
评论列表(0条)