({ title, subTitle, image })所有 3 都默认为anytype 并且我应该能够将它们设置为 astring
除非有更具体的类型将图像的类型设置为 a URL?我只是使用 Expo 中的默认选项卡模板。它确实使用了TypeScript。
我可能更喜欢将它们设置为inline,但也不反对尝试接口。我认为这只是冒号字符串
: string
但我必须在语法中遗漏一些东西,因为到目前为止它并不喜欢那样。
import React, { FC } from 'react'
import { ImageBackground, StyleSheet, Text, View } from 'react-native'
import colors from '../constants/Colors'
import AppText from './AppText'
// interface AppCardProps {
// title: string;
// subTitle: string;
// image: string;
// }
export default function AppCard({ title, subTitle, image }) {
return (
<View style={styles.card}>
<ImageBackground
style={styles.image}
source={image} />
<View style={styles.detailsContainer}>
<AppText style={styles.title}>{title}</AppText>
<AppText style={styles.subTitle}>{subTitle}</AppText>
</View>
</View>
)
}
const styles = StyleSheet.create({
card: {
borderRadius: 15,
backgroundColor: colors.white,
marginBottom: 20,
overflow: "hidden",
// width: 360,
width: "90%",
},
detailsContainer: {
padding: 20,
},
image: {
// width: 360,
// width: "100%",
height: 200,
// resizeMode: "cover",
justifyContent: "center",
},
subTitle: {
color: colors.secondary,
fontWeight: "bold",
},
title: {
marginBottom: 7,
},
})

