Comments (5)
Hi Eric,
There are several aspects to this ticket and I'll try to address all of them:
1.) Just to explain the overall motivation (even though it might be clear to you already, anyway): event.getParameter("xyz")
is no longer correct when event
is simply typed as sap.ui.base.Event
. Yes, this is true and intended and a good thing that is in line with what you expect from TypeScript, even though - as often in TypeScript - it forces you to write a bit more or express things in a more precise way. Being able to put in any string without any check and then getting something back that is typed as any
was a typing gap in the UI5 types. Now each event type knows which parameters it has and how they are typed. This means you get the existing parameter names as suggestions and won't accidentally mis-type them or use parameters that don't exist. Plus the result already has the correct type. This is exactly what TypeScript is used for. And as the base type Event
does not have parameter "xyz", TypeScript will let you know that accessing it is wrong. So this new behavior is definitely intended.
2.) The following code does not work and this is a bug:
onDropFile(event: DropInfo$DropEvent) {
const browserEvent = event.getParameter("browserEvent") as DragEvent;
The "browserEvent" parameter is typed as UI5 Event, hence TypeScript complains about the cast to the browser's DragEvent
(because "the types do not sufficiently overlap"). The parameter should rather already be typed as DragEvent
, which would make the typecast in the application code unneeded. I'm not sure whether this is a bug in the documentation of the DropInfo
's Drop
event or in the type generation: the DropInfo indeed documents it as Event
, not sap.ui.base.Event
, and in the code editor it is understood as browser event. Somewhere along the way it is turned into a UI5 event, though. We need to investigate and fix, but for the time being you can write:
onDropFile(event: DropInfo$DropEvent) {
const browserEvent = event.getParameter("browserEvent") as unknown as DragEvent;
With this, the subsequent access to the dataTransfer
property will work just fine.
3.) For the rest I'm not totally clear what you mean: "[no] combination that works with DragEvent, and without documentation"...
Do you refer to the not-working cast to DragEvent
I explained above? Or to another issue related to a Drag*
event of DropInfo
or DragInfo
? What exactly would be the "missing documentation"? Is this complaint related to the composed names of the events not being in the UI5 API documentation or to something else?
from ui5-typescript.
Thank you @akudev for the explination, for point 3: I was refering to problem above and the documentation in https://ui5.sap.com/1.116.0/#/api/sap.ui.core.dnd.DropInfo%23events/drop not matching the type indication.
I understand what you try to achieve with the changes in 1.115, but without proper documentation a piece of code like onDescriptionSearch(event: SearchField$LiveChangeEvent) {
is hard to find the proper type, since there is no refference in the documenation to LiveChangeEvent being the type that is outputed when using livechange.
from ui5-typescript.
Ok,... for problem 2.) a fix is on its way already.
The more general problem, to rephrase it, is that the type names for the events are not documented anywhere, making it hard to know them, right?
On the one hand we hoped that the consistent <ControlName>$<EventName>Event
way how the event type names are constructed would make it easy to come up with them. E.g. for https://ui5.sap.com/1.116.0/#/api/sap.ui.core.dnd.DropInfo%23events/drop it would be the control/class name first ("DropInfo"), then a dollar sign, then the event name ("Drop") and then the constant string "Event", which makes it DropInfo$DropEvent
.
On the other hand I see why it would be better to simply have it explicitly written in the documentation.
The challenges for this are:
- In the build pipeline those event type names do not exist at all at the stage where the documentation is generated, they are only created by the dts generator for TypeScript.
- The event names are not relevant for JavaScript usage and introducing hundreds of new pages in the API documentation leads to additional clicking effort for JS users to get to the relevant definition of the sap.ui.base.Event.
- Completely changing how events are documented also seems like significant effort for the code of the SDK's API documentation.
These challenges don't make the request invalid - it totally makes sense for better TypeScript support - , but harder to implement, hence this is not a thing that will happen quickly.
Where it currently says oControlEvent [sap.ui.base.Event](https://ui5.sap.com/1.116.0/api/sap.ui.base.Event)
it should probably say DropInfo$DropEvent
. But then the "getSource" and the parameters listed below should rather go to the other linked page where DropInfo$DropEvent
is defined. This would make usage harder for everyone. Maybe a short-term alternative would be to use the "Description" column, which is so far unused, to mention the TypeScript type for the event, without a link to a dedicated page for this type? The effort would be limited if we just apply a copy of the event name generation algorithm locally.
from ui5-typescript.
A reference in the documentation would be a plus, however I think you explination with example allready clear enough (for me).
It was just bad luck that the second method I tried to correct was the one that was bugged.
from ui5-typescript.
Bug is fixed with SAP/openui5@43e032c for the 1.119 types.
The general event name issue is still open.
from ui5-typescript.
Related Issues (20)
- QUnit not recognized when using @sapui5/ts-types[-esm] HOT 7
- Missing working solution for event.getParameter("value") HOT 3
- Can't lower the log level HOT 5
- Type issue with `1.115` upgrade HOT 6
- RouteInfo arguments type HOT 6
- Documentation / Feature request: How to use controller extensions in TS? HOT 8
- Issue with SelectionController taking sId as mSettings HOT 1
- How to create a typed view in SAP UI5 typescript HOT 1
- Missing type definition for `sap.m.table.ColumnWidthController` HOT 4
- Wrong source type for generated type ODataModel$DataReceivedEvent HOT 1
- [ts-interface-generator] Provide a way to annotate control properties with a TS type (which might be narrower than the UI5 one)
- [ts-interface-generator] Check what happens when overridden setters and getters narrow down the type of a property
- @deprecated tag in TS Definitions should be on the last position HOT 2
- [ts-interface-generator] Interface for ManagedObject based Class Instances
- [ts-interface-generator] Generate fully qualified module names in interface for seamless use with tsc declarations
- Productive use vs. undefined support status. HOT 3
- @sapui5/types 1.121.1, 1.121.2(?) and 1.122.1: 'JQuery' only refers to a type, but is used as namespace here. HOT 1
- Regression in @sapui5/types of 1.122.1 with tsconfig for wdi5 HOT 5
- Possible issue: too many classes are abstract? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ui5-typescript.