很多时候我想做一些类似的事情
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>'.
有什么想法如何处理这个问题吗?
我有一个用例,我想将字符串类型拆分为记录。
例子:
const string = "Thank you"
Run Code Online (Sandbox Code Playgroud)
我想把它转换成
Record<'Thank' | 'you', string>
Run Code Online (Sandbox Code Playgroud)
有什么简单的方法可以实现这一目标吗?
提前致谢