Kri*_*ool 7 typescript react-native
很多时候我想做一些类似的事情
const styles = StyleSheet.create({
square: (size: number) => ({
width: size,
height: size,
}),
})
Run Code Online (Sandbox Code Playgroud)
现在这不起作用,因为我得到了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,
}),
})
Run Code Online (Sandbox Code Playgroud)
但后来我明白了Type 'Style' does not satisfy the constraint 'NamedStyles<any> | NamedStyles<Style>'.
有什么想法如何处理这个问题吗?
Jer*_*ebe -1
我认为 StyleSheet 不支持在其键中包含函数。它的作用类似于网络上的样式表。我怀疑你之前所做的事情不受支持,但现在你使用 TypeScript,它强制执行这一点。
https://facebook.github.io/react-native/docs/stylesheet.html
归档时间: |
|
查看次数: |
4687 次 |
最近记录: |