StyleSheet.create"未被流程覆盖"

Dan*_*ore 22 css flowtype react-native

我在一个带有核素的反应原生项目中使用流量0.42.0.

使用默认项目,我收到以下消息:

在此输入图像描述

以下错误:

> 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
Run Code Online (Sandbox Code Playgroud)

这个问题(https://github.com/flowtype/flow-typed/issues/631)似乎表明正确的类型是StyleSheet.Styles,但这给了我相同的消息(和上面相同的错误):

在此输入图像描述

有什么方法可以在这里进行适当的流动打字吗?

作为参考,完整的文件是:

/**
 * 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);
Run Code Online (Sandbox Code Playgroud)

编辑升级到流程0.45.0后,根据评论,我的文件不再出现问题,但反应本身失败并出现以下错误:https://pastebin.com/raw/Ngpagayi

Cod*_*ngh 4

该警告是因为第三方尚未将流量整合到他们的终端。在我们的例子中,StyleSheet 给出了警告,因此 React Native 是没有集成流程的第三方。React Native只在某些组件中包含流程,这些组件可能只是核心组件,并且是由他们官方声明的。

正如您所说,react-native 在样式表中使用流程,所以我得出了一个结论:

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

type Props = {
    style?: StyleObj,
};
Run Code Online (Sandbox Code Playgroud)

另一种方式就是升级流量。

干杯:)