2017-05-07 67 views
11

我在使用核素的原生項目中使用流量0.42.0。StyleSheet.create「不在流程中」

使用默認的項目,我得到以下信息:

enter image description here

隨着以下錯誤:

> flow check 
index.ios.js:40 
40:    <View style={style.container}> 
            ^^^^^^^^^ property `container`. Property cannot be accessed on possibly undefined value 
40:    <View style={style.container}> 
           ^^^^^ undefined 

index.ios.js:40 
40:    <View style={style.container}> 
            ^^^^^^^^^ property `container`. Property not found in 
40:    <View style={style.container}> 
           ^^^^^ Array 

index.ios.js:41 
41:     <Text style={style.welcome}> 
             ^^^^^^^ property `welcome`. Property cannot be accessed on possibly undefined value 
41:     <Text style={style.welcome}> 
            ^^^^^ undefined 

index.ios.js:41 
41:     <Text style={style.welcome}> 
             ^^^^^^^ property `welcome`. Property not found in 
41:     <Text style={style.welcome}> 
            ^^^^^ Array 

index.ios.js:44 
44:     <Text style={style.instructions}> 
             ^^^^^^^^^^^^ property `instructions`. Property cannot be accessed on possibly undefined value 
44:     <Text style={style.instructions}> 
            ^^^^^ undefined 

index.ios.js:44 
44:     <Text style={style.instructions}> 
             ^^^^^^^^^^^^ property `instructions`. Property not found in 
44:     <Text style={style.instructions}> 
            ^^^^^ Array 

index.ios.js:47 
47:     <Text style={style.instructions}> 
             ^^^^^^^^^^^^ property `instructions`. Property cannot be accessed on possibly undefined value 
47:     <Text style={style.instructions}> 
            ^^^^^ undefined 

index.ios.js:47 
47:     <Text style={style.instructions}> 
             ^^^^^^^^^^^^ property `instructions`. Property not found in 
47:     <Text style={style.instructions}> 
            ^^^^^ Array 


Found 8 errors 

這個問題(https://github.com/flowtype/flow-typed/issues/631)似乎表明,正確的類型是StyleSheet.Styles,但是這給了我相同的消息(以及來自上面的相同錯誤):

enter image description here

有什麼辦法可以讓我在這裏得到正確的流式打字嗎?

僅供參考,完整的文件是:

/** 
* Sample React Native App 
* https://github.com/facebook/react-native 
* @flow 
*/ 

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View 
} from 'react-native'; 

export default class PartalkReact extends Component { 
    render() { 
     return (
      <View style={styles.container}> 
       <Text style={styles.welcome}> 
        Welcome to React Native! 
       </Text> 
       <Text style={styles.instructions}> 
        To get started, edit index.ios.js 
       </Text> 
       <Text style={styles.instructions}> 
        Press Cmd+R to reload,{'\n'} 
        Cmd+D or shake for dev menu 
       </Text> 
      </View> 
     ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    justifyContent: 'center', 
    alignItems: 'center', 
    backgroundColor: '#F5FCFF', 
    }, 
    welcome: { 
    fontSize: 20, 
    textAlign: 'center', 
    margin: 10, 
    }, 
    instructions: { 
    textAlign: 'center', 
    color: '#333333', 
    marginBottom: 5, 
    }, 
}); 

AppRegistry.registerComponent('PartalkReact',() => PartalkReact); 

編輯升級到流動0.45.0,按照該意見,我不再有我的文件的問題,但反應本身出現故障時與後以下錯誤:https://pastebin.com/raw/Ngpagayi

回答

2

該警告是因爲第三方尚未將流程集成到其結尾。在我們的案例中,StyleSheet正在發出警告,因此原本是沒有整合流程的第三方。 React native只包含在某些組件中的流程可能是核心流程,並且由它們正式聲明。

至於說通過你的反應本地使用流量的樣式表,所以我得出一個結論:

import type { StyleObj } from 'react- 
native/Libraries/StyleSheet/StyleSheetTypes'; 

type Props = { 
    style?: StyleObj, 
}; 

另一種方法是升級流程。

Cheers :)

+0

但是原生的源代碼在'create'函數上有流式輸入。見https://github.com/facebook/react-native/blob/master/Libraries/StyleSheet/StyleSheet.js –

+0

此外,似乎我不能cmd +點擊創建功能跳轉到它,這表明由於某些原因,該流程不解析原始來源。 –

+0

請參閱編輯。 – Codesingh

相關問題