1. 程式人生 > 其它 >Property ‘next‘ does not exist on type ‘Component<any, {}, any>‘問題的解決方法

Property ‘next‘ does not exist on type ‘Component<any, {}, any>‘問題的解決方法

技術標籤:typescript

場景:使用antd的Carousel元件時,自定義左右切換按鈕,觸發元件的next(),prev()方法時報錯

錯誤寫法:

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

handleNext是我自定義的按鈕的切換下一個圖片方法,通過refs獲取Carousel元件例項,呼叫Carousel元件的next()方法

報錯截圖:
在這裡插入圖片描述
Property ‘next’ does not exist on type ‘Component<any, {}, any>’

解決方案:

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