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

问题描述 投票:1回答:1

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

import image from './avatar.png'

type Avatar = {
  img: ???   // what is the type of image resource?
};
const Avatar = ({ img }: Avatar) => (<Icon img={img}>)
react-native flowtype
1个回答
0
投票

谢谢@Dan。你是对的。

type Avatar = {
  img: number
};

在RN中,我们经常使用require('imagepath')作为Image组件的源。如下所示,require('imagepath')返回的类型是number。我刚试过,它有效。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.