Я создаю модуль входа в систему с помощью mongodb, выражаю и реагирую, но при создании этого я столкнулся с ошибкой истории свойств, которая не существует:
Property 'history' does not exist on type 'Readonly & Readonly<{ children?: ReactNode; }>'.ts(2339)
import React, { Component } from 'react'
import { login } from './userfunctions'
interface userprops{}
interface data{
email:string;
password:string;
errors: string;
}
// основной класс:
class Login extends Component<userprops, data> {
constructor(props: userprops) {
super(props)
this.state = {
email: '',
password:'',
errors: ''
}
this.onChange = this.onChange.bind(this) //binding the function
this.onSubmit = this.onSubmit.bind(this) //binding the function
}
onChange(e:any) { //on change function
this.setState({ email: e.target.value })
}
onSubmit(e:any) { //on submitting the form in render function this function will fire
e.preventDefault()
const user = {
email: this.state.email,
password: this.state.password
}
login(user).then(res => { //I had created login function in another component
if (res) {
this.props.history.push(`/profile`) //this line is giving error
}
})
}
render() {
//rendering data
}
export default Login
сообщение об ошибке :
Property 'history' does not exist on type 'Readonly & Readonly<{ children?: ReactNode; }>'.ts(2339)
Я пробовал много вещей, но эта ошибка не исчезает
это должно работать
Большое спасибо. Моя проблема была решена путем добавления интерфейса userprops{history:any}





я думаю, вы используете реактивный маршрутизатор
если это так, вы можете расширить свой интерфейс точным типом, какой маршрутизатор передаст вашему компоненту
import { RouteComponentProps } from 'react-router-dom';
interface userprops extends RouteComponentProps {}
В вашем
historyинтерфейсе нетuserprops.