I know that I am late for the game, but I came across the same problem and preferred this solution (I hate using "any", as this partly affects the purpose of Typescript, although sometimes this is the only option):
import { Component } from "react"; import { StyleSheet, Text, View } from "react-native"; interface Props { } interface State { } interface Style { container: React.ViewStyle, welcome: React.TextStyle } const styles = StyleSheet.create<Style>({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF", }, welcome: { fontSize: 20, textAlign: "center", margin: 10, } }); export class App extends Component<Props, State> { render() { return ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> </View> ); } }
If we say StyleSheet.create, the style type for creating the build error will be allowed.
source share