I can't figure out how to annotate dateObj parameter in handleDateChange function I've
App.tsx
import { useState } from 'react';
import logo from './logo.svg';
import './App.css';
import { DatePicker } from 'antd'; // for css
import moment from 'moment';
const App = () => {
const [date, setDate] = useState(new Date())
const handleDateChange = (dateObj: Date, dateStr: string) => {
setDate(dateObj);
}
return (
<div className="App">
<DatePicker defaultValue={moment(date)} onChange={handleDateChange} />
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
Here's what tslint says -
Type '(dateObj: Date, dateStr: string) => void' is not assignable to type '(date: Moment, dateString: string) => void'. Types of parameters 'dateObj' and 'date' are incompatible. Type 'Moment' is not assignable to type 'Date'. Property 'toDateString' is missing in type 'Moment'
But I'm not sure how to overcome this.
