【发布时间】:2019-09-24 16:11:31
【问题描述】:
很多时候我想做类似的事情
const styles = StyleSheet.create({
square: (size: number) => ({
width: size,
height: size,
}),
})
现在这不起作用,因为我得到了Type '(size: number) => { width: number; height: number; }' is not assignable to type 'ViewStyle | TextStyle | ImageStyle'。我试过做类似的事情
interface Style {
square: (width: number) => ViewStyle
}
const styles = StyleSheet.create<Style>({
square: (size: number) => ({
width: size,
height: size,
}),
})
然后我得到Type 'Style' does not satisfy the constraint 'NamedStyles<any> | NamedStyles<Style>'.
任何想法如何处理这个问题?
【问题讨论】: