Ho ricevuto un errore molto strano in merito a TypeScript che mi dice che le stringhe letterali non corrispondono. (Dattiloscritto v1.8)Errore di scrittura letterale React Native String di tipo
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>
);
}
}
Errore: src \ client \ index.ios.tsx (19,15): l'errore TS2322: Tipo '{fontSize: il numero; textAlign: string; margine: numero; } 'non è assegnabile al tipo' TextStyle '. I tipi di proprietà "textAlign" non sono compatibili. Il tipo 'stringa' non è assegnabile al tipo '"auto" | "sinistra" | "giusto" | "centro"'. Il tipo 'stringa' non è assegnabile al tipo '"centro"'.
Ho installato i tipi corretti. Sembra che quanto segue non funzioni in TypeScript.
interface Test {
a: "p" | "q"
}
let x : Test;
let y = {
a: "p"
}
x = y;
Fonte: https://blog.lopezjuri.com/2015/12/30/react-native--typescript/
Ho questo problema con Typescript 2.1.x pure. – Learner