1
我試圖將流實現到我的React應用程序中。到目前爲止它工作正常,但我遇到了默認值的問題。React無狀態組件上的流類型別名
函數頭是:
const FormControls = ({ form, controls = null, labels = {} }: { form: any, controls: ?TFormControls, labels?: TFormControlLabels}) => (
爲TFormControls類型別名是:
type TFormControls = {
onSubmit?: boolean,
onReset?: boolean,
onClear?: boolean
}
我所期望的,因爲我把也許運營商那裏controls: ?TFormControls
,它要麼是我的type-alias或null/undefined,但流程告訴我:
src/components/forms/FormControls.jsx:35
35: const FormControls = ({ form, controls = null, labels = {} }: { form: any, controls: ?TFormControls, labels?: TFormControlLabels}) => (
^^^^^^^^ null. This type is incompatible with
35: const FormControls = ({ form, controls = null, labels = {} }: { form: any, controls: ?TFormControls, labels?: TFormControlLabels}) => (
^^^^^^^^ object type
src/components/forms/FormControls.jsx:35
35: const FormControls = ({ form, controls = null, labels = {} }: { form: any, controls: ?TFormControls, labels?: TFormControlLabels}) => (
^^^^^^^^ object type. This type is incompatible with
35: const FormControls = ({ form, controls = null, labels = {} }: { form: any, controls: ?TFormControls, labels?: TFormControlLabels}) => (
^^^^^^^^ null
任何指針wo非常歡迎!
編輯:按照要求,錯誤的完整功能的example
你可以發佈一個完整的例子嗎?這會讓那些試圖幫助你的人更容易。你甚至可以在http://flowtype.org/try中發佈一個鏈接 –