Я разрабатываю свое первое приложение в React-Native с помощью TS, и когда я пытаюсь использовать свой компонент с реквизитами, я получаю некоторую ошибку в своей IDE, но приложение работает с Expo....
Ошибка на "Кнопка Preset"
import React from "react";
import { StyleSheet, Text, View, TextInput, Button } from "react-native";
import ButtonPreset from "./Components/reusable/ButtonPreset";
export interface ButtonPrefab {
_pressAction(): void;
pressAction(): void;
}
export default class App extends React.Component {
_pressAction = () => {
console.info("Hello");
}
title: string = "Se connecter";
render() {
return (
<View style = {styles.container}>
<View style = {styles.header}>
<Text style = {styles.headerTitle}>Splizi</Text>
</View>
<View style = {styles.login}>
<TextInput style = {styles.input} placeholder = "E-mail" />
<TextInput style = {styles.input} placeholder = "Mot de passe" />
<ButtonPreset pressAction = {this._pressAction} title = {this.title} />
</View>
</View>
);
}
}
import React from "react";
import { StyleSheet, Button } from "react-native";
type ButtonPresetProps = {
pressAction: () => void;
title: string
}
class ButtonPreset extends React.Component<ButtonPresetProps> {
render() {
return <Button onPress = {this.props.pressAction} title = {this.props.title} />;
}
}
const styles = StyleSheet.create({
// input: {
// marginLeft: 40,
// marginRight: 40,
// marginBottom: 20,
// height: 60,
// borderRadius: 50,
// borderWidth: 0.5,
// paddingRight: 20,
// paddingLeft: 20,
// fontSize: 18,
// borderColor: '#d6d6d6',
// backgroundColor: '#ffffff',
// }
});
export default ButtonPreset;
Я получаю следующую ошибку. Пожалуйста, помогите мне решить эту проблему.
Type '{ pressAction: () => void; title: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<{ children?: ReactNode; }>'. Property 'pressAction' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<{ children?: ReactNode; }>'.
@ShaunLuttin Готово, спасибо






Судя по сообщению об ошибке, ButtonPreset нужен соответствующий тип реквизита.
type ButtonPresetProps = {
pressAction: () => void;
title: string;
};
class ButtonPreset extends React.Component<ButtonPresetProps> {
// other code omitted
}
export interface ButtonPrefab {
_pressAction:() => void;
pressAction:() => void;
}
export default class App extends React.Component<ButtonPrefab> {}
Попробуй это.
Также включите код компонента
ButtonPreset.