feat(framework): add .currentTarget
to the type of event handler in TSX and UI5CustomEvent
#10957
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.
The generated event handlers for events described in
eventDetails
now have the correct type for thee.currentTarget
parameterAdditionally, the
UI5CustomEvent
helper also adds the correct type to the event parametere.currentTarget
An event handler no longer has to use type assertions
Before:
This works, but the same event handler is also attached to a ui5-slider and the
e.target.value
is a number in that case which goes unnoticed because of theas Input
type assertion.After
Implementation note
Event handlers are contravariant (an event handler that takes a subclass as a parameter cannot be assigned to a property in the base class that takes the base class as a parameter).
To circumvent this, the generated event handlers are using the method notation so that typescript handles them as bivariant
More info in the
strictFunctionTypes
compiler option here:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-6.html#strict-function-types