简体   繁体   English

类型 '{ children?: ReactNode; 上不存在属性 'firebase' }' 如何正确注释?

[英]Property 'firebase' does not exist on type '{ children?: ReactNode; }' how to propperly annotate?

I'm providing my firebase object through a higher order component like this:我通过像这样的高阶组件提供我的 firebase object:

const FirebaseContextInterfaceLocal: FirebaseContextInterface = {
  value: new Firebase()
}

ReactDOM.render(
  <Router history={history}>
    <FirebaseContext.Provider value={FirebaseContextInterfaceLocal}>
      <App />
    </FirebaseContext.Provider>
  </Router>,
  document.getElementById('root')
)

And after that I'm using it like this:之后我像这样使用它:

const ForgotPassword: React.FC = ({ firebase }) => {

}

export default withFirebase(ForgotPassword)

But I'm getting the following error:但我收到以下错误:

Property 'firebase' does not exist on type '{ children?: ReactNode; }'.

I'm trying to find out how to properly annotate this but I can't find any good explanation.我试图找出如何正确注释它,但我找不到任何好的解释。 Any help will be very appreciated!任何帮助将不胜感激!

use value key instead of firebase使用value键代替 firebase

const ForgotPassword: React.FC = ({ value }) => {

}

export default withFirebase(ForgotPassword)

or try to change the property of FirebaseContextInterfaceLocal to:或尝试将FirebaseContextInterfaceLocal的属性更改为:

const FirebaseContextInterfaceLocal = {
  firebase: new Firebase()
}

ReactDOM.render(
  <Router history={history}>
    <FirebaseContext.Provider firebase={FirebaseContextInterfaceLocal.firebase}>
      <App />
    </FirebaseContext.Provider>
  </Router>,
  document.getElementById('root')
)

So you can do this:所以你可以这样做:

const ForgotPassword: React.FC = ({ firebase }) => {

}

export default withFirebase(ForgotPassword)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型 '{ children?: ReactNode; 上不存在属性 'onClick' }' - Property 'onClick' does not exist on type '{ children?: ReactNode; }' 属性不存在于类型 'IntrinsicAttributes & { children?: ReactNode; }' - Property does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }' "<i>TypeScript error: Property &#39;children&#39; does not exist on type &#39;{ children?: ReactNode;<\/i> TypeScript 错误:类型 &#39;{ children?: ReactNode; 上不存在属性 &#39;children&#39;<\/b> <i>}&#39;<\/i> }&#39;<\/b>" - TypeScript error: Property 'children' does not exist on type '{ children?: ReactNode; }' 属性 &#39;XYZ&#39; 不存在于类型 &#39;Readonly&lt;{ children?: ReactNode; }&gt; 和只读&lt;{}&gt;&#39; - Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>' TypeScript 错误:属性“children”在类型“ReactNode”上不存在 - TypeScript error: Property 'children' does not exist on type 'ReactNode' 类型'IntrinsicAttributes &amp; PhoneInputProps &amp; { children?: ReactNode; 上不存在属性'ref' } - Property 'ref' does not exist on type 'IntrinsicAttributes & PhoneInputProps & { children?: ReactNode; } &#39;IntrinsicAttributes &amp; IntrinsicClassAttributes 类型上不存在属性<DatePicker> &amp; Readonly&lt;{ children?: ReactNode; }&gt; ...&#39; - Property does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<DatePicker> & Readonly<{ children?: ReactNode; }> …' "<i>TypeScript: Property &#39;data&#39; does not exist on type &#39;{ children?: ReactNode;<\/i> TypeScript:类型&#39;{ children?:ReactNode;上不存在属性&#39;data&#39;<\/b> <i>}&#39;.<\/i> }&#39;。<\/b> <i>ts(2339)<\/i> ts(2339)<\/b>" - TypeScript: Property 'data' does not exist on type '{ children?: ReactNode; }'. ts(2339) 属性 'setUser' 不存在于类型'Readonly&lt;{}&gt; &amp; Readonly&lt;{ children?: ReactNode; }&gt;' - Property 'setUser' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>' 类型 &#39;{ props: ReactNode; 上不存在属性 &#39;className&#39; }&#39; - Property 'className' does not exist on type '{ props: ReactNode; }'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM