2017-05-07 72 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

相关问题