Property'next' does not exist on type'Component<any, {}, any>'

Scenario: When using the Carousel component of antd, customize the left and right switch buttons, and an error will be reported when the next() and prev() methods of the component are triggered

Wrong wording:

  handleNext(){
    
    
    this.refs.img.next()
  }
  <Carousel
     dots={
    
    false}
     ref="img"
   >
	...
   </Carousel>

handleNext is my custom button to switch the next picture method, get the Carousel component instance through refs, and call the next() method of the Carousel component

报错截图:
Insert picture description here
Property ‘next’ does not exist on type ‘Component<any, {}, any>’

solution:

  handleNext(){
    
    
    (this.refs.img as any).next();
  }

Guess you like

Origin blog.csdn.net/sunzhen15896/article/details/111359711