2017-06-26 48 views
0

これは、実際には、ReactまたはReact Nativeの使用タイプについてはドキュメントレスです。リアクションエレメントのフロータイプ

の要素タイプがrender() functionにあることがわかりました。

// @flow 
import React from 'react'; 
import { Text } from 'react-native'; 

function greetingTextNode(string: string): React$Element<any> { 
    return (
    <Text>Greeting, { string }.</Text> 
) 
} 

が、それはコンソールでflowtypeエラーを示しています:だから私は私のコードでこれを試してみてください

20:  <Text>Greeting, { string }.</Text> 
     ^^^^^^ Text. This type is incompatible with 
97: type _ReactClass<DefaultProps, Props, Config: $Diff<Props, DefaultProps>, C: React$Component<DefaultProps, Props, any>> = Class<C>; 
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React$Component. See lib: /private/tmp/flow/flowlib_243350bf/react.js:97 

はどのように反応要素のフロータイプを修正することができますか?

答えて

0

試してみてください。

function greetingTextNode(str: string): React.Element<*> { 
    return (
    <Text>Greeting, { str }.</Text> 
) 
} 

ジェネリック型で `*`、 `ないany`を使用して、なぜあなただ​​けではない正しい構文

+0

、正しい考え方を持っていましたか? –

+0

'*'を使用すると、そのタイプを推論するためにFlowに指示します。 https://flow.org/en/docs/types/utilities/#toc-the-existential-type – evanflash

関連する問題