Css StyleSheet.create";不包含在“流量”中;

Css StyleSheet.create";不包含在“流量”中;,css,react-native,flowtype,Css,React Native,Flowtype,我在一个带有核素的react native项目中使用flow 0.42.0 对于默认项目,我得到以下消息: 以及以下错误: > flow check index.ios.js:40 40: <View style={style.container}> ^^^^^^^^^ property `container`. Property cannot be accessed on po

我在一个带有核素的react native项目中使用flow 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

编辑升级到flow 0.45.0后,根据评论,我的文件中不再有问题,但反应本身失败,出现以下错误:

警告是因为第三方未将flow集成到其端部。在我们的例子中,样式表给出了警告,因此react native是未集成流的第三方。React native仅包含在某些组件中的流可能是核心流,并且由它们正式声明

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

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

type Props = {
    style?: StyleObj,
};
另一种方法是升级流


干杯:)

对于2018年末仍遇到这种情况的人,首选解决方案改为:

import type {
  ViewStyleProp,
  TextStyleProp,
  ImageStyleProp,
} from 'react-native/Libraries/StyleSheet/StyleSheet';

资料来源:

我一直在使用以下方法,取得了相当大的成功
如果使用不存在的样式属性并启用代码完成,则会显示错误

const rawStyles = { ... }
export const styles: typeof rawStyles = StyleSheet.create(rawStyles)

将此添加到您的类之上:

type Props = {
    style?: StyleSheet.Styles;
}; 

但是react原生源在
create
函数上有流类型。另请参见,似乎我无法cmd+单击create函数跳转到它,这表明出于某种原因,flow没有解析react原生源代码;我还没有反应过来。我该如何使用您提供的摘录?只需将其添加到文件中就不会产生任何差异。你能修改我的示例文件作为演示吗?让我们看看。你有这个代码在实际设置中工作吗?如果是这样的话,您能把
.flowconfig
.package.json
传递给我们吗?我还是无法让它为我的生活工作。
type Props = {
    style?: StyleSheet.Styles;
};