fix(types): include optional nativeEvent.target on picker events - #1064
Open
cpruijsen wants to merge 1 commit into
Open
fix(types): include optional nativeEvent.target on picker events#1064cpruijsen wants to merge 1 commit into
cpruijsen wants to merge 1 commit into
Conversation
iOS native view events include the React tag RN injects as nativeEvent.target, but the shared TypeScript type omitted it, so accessing that field was a type error even though the value is present at runtime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional
target?: numbertoDateTimePickerEventandDateTimePickerChangeEvent(TypeScript and Flow) and documents it. Runtime event construction is unchanged: Android still omits the field; iOS dismiss still omits it.Fixes #927.
iOS
onChange/onValueChangeevents includenativeEvent.target(the React tag React Native injects on native view events); Android dialogs omit it, because the picker is not a view. The shared TypeScript type only listedtimestampandutcOffset, so accessingtargetwas a type error even though iOS returns it. Reporter: compact mode on iOS, Expo SDK 51, intersectingDateTimePickerEventwith{ nativeEvent: { target?: number } }to compile.The types use optional
targeton the shared eventnativeEventrather than platform-specific event types (IOSDateTimePickerEventvsAndroidDateTimePickerEvent) or stripping iOS extras so both sides match the old smaller type. Flow already modelsnativeEventas an open object; optionaltargetis the smallest TypeScript equivalent, matches the reporter's workaround, and keeps Android object literals assignable. Stripping iOStargetwould break the reporter. Can switch to platform-specific event types if that is preferred.Test Plan
What's required for testing (prerequisites)?
A TypeScript consumer of
DateTimePickerEvent. No device required for the type change;yarn test test/types.test.jstypechecks a fixture undertsc --strict.What are the steps to reproduce (after prerequisites)?
onChangeas(event: DateTimePickerEvent) => { event.nativeEvent.target }.TS2339Property 'target' does not exist.targetisnumber | undefined. An Android-shaped event{ type: 'set', nativeEvent: { timestamp, utcOffset } }still typechecks.Optional on a simulator: compact iOS picker, log
event.nativeEventon change:targetis present; Android dialog change:targetis absent.Compatibility
Checklist
README.mdexample/App.js)