2017-09-01 10 views
0

我有一個父組件,這是一個非常縮小版本。流量問題我無法克服。通過道具購買沒有確認形狀

我定義類型狀態(如示例所示).....然後我將它們的一部分(它們的值)傳遞給子組件。那個子組件(在一個單獨的文件中)再次定義了它的道具......但是我在父項中的每一個道具都會出錯。真氣。

每個道具傳遞給「MyChildComponent」,我得到這個錯誤:

陣營元素MyChildComponent的道具。這種類型與對象類型

type State = { 
    name: string, 
    age: number, 
    shoe: number, 
    hair: string 
} 

class Dude extends component<void, Props, State> { 
    props: Props; 
    state: State; 

    // these values get over-written by some ajax call 
    constructor() { 
    this.state = { 
     name: 'george', 
     age: 999, 
     hair: 'brown', 
     shoe: 11 
    } 

    displaySomeComponent =(): React.Element<*> => { 
    const { name, age, hair } = this.state; 
    return (
    // EACH ONE OF THESE GIVES AN ERROR 
    //Flow: props of React element `MyChildComponent`. This type is incompatible with object type 
     <MyChildComponent 
     name={name}, 
     age={age}, 
     hair={hair} 
     /> 
    ) 

    } 
} 

// In a separate file for MyChildComponent 
// No errors in this file 
type Props = { 
    name: string, 
    age: number, 
    hair: string 
} 
class MyChildComponent extends component<void, Props, void> { 
    props: Props; 

    render() { 
    // all renders fine 
    } 
} 

我在我束手無策不兼容。我不明白髮生了什麼事情,因爲我已經將事情傳遞到了許多子組件中,但是這正在悄悄癱瘓。我認爲這可能與解構有關?

+0

您使用的是什麼版本的Flow?看起來不到0.53,但更具體可能會有所幫助。 – Adam

+0

我正在使用流倉:0.52 –

回答

0

嗯,這很難說。如果我修復了一些語法錯誤,在Flow 0.54中似乎可以正常工作:my version

要追查什麼是錯誤的,您可以嘗試添加類型聲明以查看錯誤發生的位置。就像在父級渲染方法中,在解構下,嘗試添加name: string;並查看Flow是否對此抱怨。

相關問題