Change default original event type from undefined to unknown #2243
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.
Launch Checklist
Currently, the default type for originalEvent on a MapLibreEvent is "undefined." This can lead to type errors when handling some events unless the type for originalEvent is specified on the handler, even when we may not care about the type of orginalEvent at all. For example, let's say I want to handle a zoom event. If I define an event handler like this:
onZoom(event: MapLibreEvent) {}
I will get a type error if I try to subscribe to a zoom event using that callback, because that event is typed as
MapLibreEvent<MouseEvent | TouchEvent | WheelEvent | undefined>
. The TypeScript compiler complains about the three non-undefined event types being unassignable to undefined.Moreover, the type "unknown" is more correct here anyway, as the base case is not knowing what the type is. In the case where the handler doesn't care about originalEvent, using unknown as the default instead means you don't have to provide the type at all.
CHANGELOG.md
under the## main
section.