如何为React Native资源执行流类型注释?

时间:2017-05-19 08:57:51

标签: react-native flowtype

我想将图像传递给React Native组件。图像资源的类型是什么?

import image from './avatar.png'

type Avatar = {
  img: ???   // what is the type of image resource?
};
const Avatar = ({ img }: Avatar) => (<Icon img={img}>)

1 个答案:

答案 0 :(得分:0)

感谢@Dan。你是对的。

nodes = [
    ['ID', 'Label', 'Color'],
    [0,'WAKA WANNA BE SOURCE','#F27420'],
    [1,'WAKA WANNA BE TARGET','#4994CE'],
    [2,'WAKA DON\'T KNOW WHO WANNA BE','#FABC13'],

]
links = [
    ['Source','Target','Value','Link Color'],
    [0,1,10,'rgba(253, 227, 212, 1)'],
    [0,2,10,'rgba(242, 116, 32, 1)'],
    [2,1,10,'rgba(253, 227, 212, 1)'],
]

在RN中,我们经常使用type Avatar = { img: number }; 作为Image组件的来源。如下所示,返回的类型require('imagepath')require('imagepath')。我刚刚尝试过,它有效。

enter image description here