是否有任何本机样式的流类型定义

是否有任何本机样式的流类型定义

本文介绍了是否有任何本机样式的流类型定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个本机组件,并使用Flow来定义这样的属性类型:

I'm making a react native component and using Flow to define the property types like this:

type Props = {
    text: string,
    textStyle: object
}

然后将这些属性传递到组件内部的Text组件.是否有任何针对React-native的Flow类型定义,可以让我做这样的事情:

Those properties are then passed to the Text component inside my component. Are there any Flow type definitions for react-native that will allow me to do something like this:

textStyle: TextStyle

Now Flow现在可以检查textStyle值是否仅包含Text组件样式允许的键.

Now Flow would be able to check that the textStyle value contains only keys that are allowed for Text component style.

我看到有TypeScript(React.TextStyle)的接口定义,但找不到Flow的任何内容.

I see that there are interface definitions for TypeScript (React.TextStyle) but can't find anything for Flow.

推荐答案

更新3:

当前的最佳做法是:

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

更新2:以下 PR 使事情变得更简单,到目前为止,流类型样式如下.

Update 2: The following PR makes things simpler, as of today flowtype styles are as follow.

type StyleValue = {[key: string]: Object} | number | false | null;
type StyleProp = StyleValue | Array<StyleValue>;

已过时::遵循PR 修复程序可以在v0.52.0中找到

Obsolete: The following PR fixes it, can be found from v0.52.0

可以执行以下操作:

// @flow

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

type Props = {
    style?: StyleObj
};

以下讨论: https://github.com/flowtype /flow-typed/issues/631#issuecomment-282009393

这篇关于是否有任何本机样式的流类型定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 14:19