簡體   English   中英

typescript 中的 React HOC 組件給出警告(從非打字稿轉換)

[英]React HOC component in typescript gives warnings (converting from non-typescript)

我在 react + typescript 中有以下簡單的 HOC 組件。

export const withFirebase = <P extends object>(
  Component: React.ComponentType<P>
) =>
  class WithFirebase extends React.Component<P> {
    render() {
      return (
        <FirebaseContext.Consumer>
          {firebase => <Component {...this.props} firebase={firebase} />}
        </FirebaseContext.Consumer>
      )
    }
  }

export default FirebaseContext

我正在將此組件從非類型腳本轉換為 typescript function 但 ESlint 給我以下錯誤:function 上缺少返回類型。 我在這里想念什么? 我應該以不同的方式編寫我的 HOC 組件嗎?

試圖在 function 上提供返回類型?

export const withFirebase = <P extends object>(
  Component: React.ComponentType<P>
): React.ComponentType<P> =>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM