我有一个样式表,我从全局样式表文件styles.ts
导入home.ts
// styles.ts
import { StyleSheet } from 'react-native'
export default {
text: StyleSheet.create({
body: {
color: 'red',
textAlign: 'center'
}
})
}
// home.ts
import globalStyles from '../constants/styles'
render() {
return <Text style={globalStyles.text.body}>Hello, tap begin to start Lesson 1</Text>
}
但即使文本在ios模拟器中正确呈现,打字稿也在抱怨,说
file: 'file:///Users/matthewchung/Documents/Cards/src/screens/HomeScreen.tsx'
severity: 'Error'
message: 'Type '{ style: { color: string; textAlign: string; }; children: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<TextProperties, ComponentState>> & Reado...'.
Type '{ style: { color: string; textAlign: string; }; children: string; }' is not assignable to type 'Readonly<TextProperties>'.
Types of property 'style' are incompatible.
Type '{ color: string; textAlign: string; }' is not assignable to type 'TextStyle'.
Types of property 'textAlign' are incompatible.
Type 'string' is not assignable to type '"center" | "auto" | "left" | "right"'.'
我不知道为什么。无论如何,任何建议都表示赞赏。