本文介绍了如何为React Native资源进行流类型注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to pass an image to a React Native component. What is the type of an image resource?

import image from './avatar.png'

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

推荐答案

感谢 @Dan .你是对的.

type Avatar = {
  img: number
};

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

In RN, we often use require('imagepath') as the source of an Image component. As you see below, the type require('imagepath') returns is a number. I've just tried, it works.

这篇关于如何为React Native资源进行流类型注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 11:32