Comments (12)
Thanks @RobertoMalatesta
The TypeScript signatures are generated from OpenUI5 api.json output, which is itself
generated from the JSDocs that are part of the OpenUI5 source code.
If you look the nav container source code in OpenUI5 you will see that the JSDocs are incorrect
and do not specify that arguments 2 and 3 are optional.
To specific an optional argument in JSDocs you would need to use square brackets.
// @param {string} [fooOptional]
// @param {string} barMandatory
See: http://usejsdoc.org/tags-type.html
Basically this needs to be fixed in the OpenUI5 sources directly.
Do you want to try creating a PR there?
from ui5-typescript.
Hi @bd82 !
The TypeScript signatures are generated from OpenUI5 api.json output [...]
JSDocs are incorrect and do not specify that arguments 2 and 3 are optional
I know it since I managed to get my own bindings some time ago.
Sometimes parameter optionality is only mentioned in the textual description.
This is the case in lots of components.
On the TS side I resolved by adding lots of union types (type|undefined) with the rationale: if the description mentions a possible optionality of the parameter add |undefined.
Then there's one other problem, Typescript-related:
if you have multiple optional parameters and if you want to skip one
basically you need to adopt the union types solution (or the boxing/unboxing approach)
This depends on the unavailability of (C#-like) named parameters in function/method calling in TS.
Do you want to try creating a PR there?
I seem to recall someone already did open it or mentioned the documentation issue in a discussion.
I suppose it won't be an easy task for the UI5 team to go after all declarations in a reasonable ETA.
(The case opened for TS bindings itself is dated 2014.)
--R
from ui5-typescript.
Sometimes parameter optionality is only mentioned in the textual description.
This is the case in lots of components.
On the TS side I resolved by adding lots of union types (type|undefined) with the rationale: if the description mentions a possible optionality of the parameter add |undefined.
That an interesting heuristic that should be considered for implementation.
There are already multiple heuristics during the transformation flow...
Then there's one other problem, Typescript-related:
if you have multiple optional parameters and if you want to skip one
basically you need to adopt the union types solution (or the boxing/unboxing approach)
This depends on the unavailability of (C#-like) named parameters in function/method calling in TS.
I solved a similar problem of optional params followed by required params by creating all possible overloads of a function/method so all possible argument lists would be valid.
However I am not sure it is true to say that any instance where there is a sequence of optional arguments
can be replaced with type unions combos because not all implementations actually
perform these type checks and assignments at runtime.
In those cases I would expect the JSDocs documentation to be corrected to represent those type unions.
from ui5-typescript.
I seem to recall someone already did open it or mentioned the documentation issue in a discussion.
I suppose it won't be an easy task for the UI5 team to go after all declarations in a reasonable ETA.
One could potentially automate this: if we have a heuristic that identifies a description that specifies an optional parameter but the parameter's JSDocs is marked as required, one could create a list of issues that need to be resolved.
In theory it may even be possible to create this in an auto-fixable manner, e.g: embedding the logic
in an eslint rule with auto-fix capabilities.
from ui5-typescript.
There are already multiple heuristics during the transformation flow...
Documentation has greatly improved in the years but still cannot IMHO used per se, whithout referring to the source, since it still shows wrong info between fields.
A simple example, let's stay on sap.m.NavContainer.to method:
pageid is marked as type string, but the description states: "... The ID or the control itself can be given."
[this affected me since I never in my code use string IDs since TypeScript (but well written JS as well) allows you to work with references and variables]:
(So, pageId should be a union type as well...)
from ui5-typescript.
That an interesting heuristic that should be considered for implementation.
Another one, more subtle is collecting all double quoted strings in the description of an argument marked as -say- string (generic string) to extract all possible values and create a string enum /string const array.
i.e. the sap.m.NavContainer.to transitionName parameter:
from ui5-typescript.
I solved a similar problem of optional params followed by required params by creating all possible overloads of a function/method so all possible argument lists would be valid.
Saw the code and liked it. 👍
And other people at SAP can assure you that I'm very spare on compliments.
from ui5-typescript.
However I am not sure it is true to say that any instance where there is a sequence of optional arguments
can be replaced with type unions combos because not all implementations actually
perform these type checks and assignments at runtime.
Hm. Interesting.
Do you have an example?
from ui5-typescript.
Regarding Incorrect / Imprecise docs:
These are interesting use cases, But we have to consider what is the scope of this project?
- Should fixing the content of the OpenUI5 docs be a part of it?
- Should we apply heuristics that would add 2 "bugs' for every 8 issues fixed?
Also consider that in the longer term this project would hopefully not be limited to only OpenUI5...
My personal opinion is that many of these things should be outside the scope
of this project, unless there are some very low hanging fruits (e.g all constructor signatures in OpenUI5 are slightly incorrect).
@codeworrior , @petermuessig what do you think?
Regarding sequence of optional parameters
I think I had some examples in an internal discussion we had months ago,
I will look for those. Anyhow this is a specific case of the scope question:
The author may have had 2 possible intents, should we guess the real intent or should
the author properly document his or hers code?
We already have quite a bit of complexity here in aligning UI5 type system assumptions with TypeScript's more robust type system, do we want to add more?
from ui5-typescript.
I could not find a specific example for sequence of optional parameters but I found a similar example
demonstrating the mis-match between the definition and implementation (this may have been fixed since...0
- scrollToElement
- In JSDocs, 2nd argument is defined as optional and 3rd argument is mandatory.
This can be done in JavaScript, but it requires some runtime magic to distinguish the arguments. - The implementation does not perform any such runtime magic so in actuality the 2nd parameter is
mandatory! - Also note that the 3rd argument is implemented as optional even though it is defined as mandatory.
- In JSDocs, 2nd argument is defined as optional and 3rd argument is mandatory.
- attachValidationSuccess
- In this case the "runtime magic" was actually implemented to properly support interweaving optional and none optional arguments.
- This is equivalent to function overloading.
The point I am trying to demonstrate is that I cannot guess the intent of the author.
In some cases there is special runtime handling of different orders of call arguments.
In other cases there are none.
from ui5-typescript.
After some more thinking these are my conclusions:
I don't think such a heuristic should be part of the dts-generator as I believe those kinds of errors
should be fixed originally in the UI5 Docs instead of adding even more complexity here.
I do believe we can help the UI5 teams to fix their Docs by creating a report/log where we detect
cases where incorrectly documented optional parameters.
I will open a new issue for the report.
from ui5-typescript.
from ui5-typescript.
Related Issues (20)
- Can't lower the log level HOT 5
- Missing documentation for event type names in SDK 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
- `@sapui5/ts-types-esm` - `sap/ui/core/Core` is incorrectly exported as an instance instead of a class HOT 1
- i can't find a way to use typescript and the flp sandbox launchpad HOT 3
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.