我试图找出expo/vector-icons,图标名的类型定义,因为我打算将它用于组件道具。
我是导入expo/vector-icons喜欢和定义像这样的接口道具,我尝试类型图标名称作为字符串。
import Icon from "@expo/vector-icons/FontAwesome"
interface Props {
icon: string
value: string
placeholder: string
onChangeText: (text: string) => void
secureTextEntry?: boolean
style: StyleProp<ViewStyle>
}我就是这么用道具的。
<Icon name={icon} size={20} style={styles.icon} />但我从打字稿中发现了错误。

发布于 2022-06-13 22:03:19
你必须改变图标道具的类型,
import { Ionicons } from '@expo/vector-icons';并使用Ionicons中的glyphMap属性,如下所示
icon: keyof typeof Ionicons.glyphMaphttps://stackoverflow.com/questions/72267427
复制相似问题