I have been getting a very strange error with regards to TypeScript telling me string literals do not match. (TypeScript v1.8)
import { Component } from "react";
import {
StyleSheet,
Text,
View
} from "react-native";
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10,
}
});
export class App extends Component<any, any> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
}
}
Error:
src\client\index.ios.tsx(19,15): error TS2322: Type '{ fontSize: number; textAlign: string; margin: number; }' is not assignable to type 'TextStyle'.
Types of property 'textAlign' are incompatible.
Type 'string' is not assignable to type '"auto" | "left" | "right" | "center"'.
Type 'string' is not assignable to type '"center"'.
I installed the correct typings. It seems that the following does not work in TypeScript.
interface Test {
a: "p" | "q"
}
let x : Test;
let y = {
a: "p"
}
x = y;
Source: https://blog.lopezjuri.com/2015/12/30/react-native--typescript/