Wrong type declaration in the onChange event
See original GitHub issueBug report
Summary
The Event received as the argument for the onChange
callback has an incorrect type declared. The type should be event.nativeEvent.timestamp
but the actual type declared is evt.nativeEvent.timeStamp
. Note the uppercase S in
timeStamp
This is not a problem since I can do what I need using the second argument on the onChange
callback or even using event.nativeEvent.timestamp
and disregarding the linter. Anyways, I thought maintainers would like to know this is happening. Hopefully it should be an easy fix for someone familiar with React Native types.
Reproducible sample code
This shows a linting error:
<DateTimePicker
value={new Date()}
mode='date'
is24Hour={false}
display='default'
onChange={evt => {
const timestamp = evt.nativeEvent.timestamp
if (timestamp) {
// handle the input change
}
}}
/>
Steps to reproduce
Using the code above the linter will complain and suggest to use evt.nativeEvent.timeStamp
instead.
Describe what you expected to happen:
I expected timeStamp
to be the property with the value, but it was timestamp
. The result was that timestamp
in the code above was always undefined
Hovering over event.nativeEvent
shows the following type:
React.BaseSyntheticEvent<Event, EventTarget & Readonly<{ timestamp: number; }>, EventTarget>.nativeEvent: Event
I was hoping the Readonly<{timestamp: number;}>
part should fix this, but I’ve been using typescript for just a few days and I don’t really know what’s going on there
Environment info
npx react-native info
output:
System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-6360U CPU @ 2.00GHz
Memory: 32.04 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.1 - /usr/local/bin/node
Yarn: 1.3.2 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Watchman: 4.7.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.0 - /usr/local/bin/pod
SDKs:
iOS SDK: Not Found
Android SDK:
API Levels: 23, 24, 26, 29
Build Tools: 23.0.1, 26.0.1, 26.0.2, 28.0.3, 29.0.2
Android NDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: /undefined - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_141 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: ~0.63.3 => 0.63.3
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
datetimepicker version: ^3.0.8
iOS / Android version: Android 11
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
This is how I got it to work if it helps
as of v6, this would look like this: