我尝试在我的StyleSheet
文件中使用一些variables
。
UI工作正常。但类型错误。
你知道怎么解决吗?
第一个
这是来自类型的错误消息。
Type 'Styles' does not satisfy the constraint 'NamedStyles<any> | NamedStyles<Styles>'.
Type 'Styles' is not assignable to type 'NamedStyles<Styles>'.
Types of property 'button' are incompatible.
Type 'buttonStyle' is not assignable to type 'ViewStyle | TextStyle | ImageStyle
3条答案
按热度按时间7ajki6be1#
添加诸如
this
之类任何类型,5t7ly7z52#
我认为StyleSheet不包含函数类型。所以我用这个方法修复了这个错误。
样式文件
无需定义样式类型。
xj3cbfub3#
您可以在组件外部使用StyleSheet. create()创建常量样式:
然后在组件中这样调用它: