sap / ui5-typescript Goto Github PK
View Code? Open in Web Editor NEWTooling to enable TypeScript support in SAPUI5/OpenUI5 projects
Home Page: https://sap.github.io/ui5-typescript
License: Apache License 2.0
Tooling to enable TypeScript support in SAPUI5/OpenUI5 projects
Home Page: https://sap.github.io/ui5-typescript
License: Apache License 2.0
The description just tells us that @ui5/dts-generator is "A low level compiler which transforms SAP UI5 api.json format". Unfortunately I can't find any indication where to find matching files or how to generate them. There are some of those files in the tests, but they don't cover all of ui5 and only one specific version. Please amend the description to tell us how to get those files.
PS: Google didn't help me either ;)
We use the types int and float to document constraints for numeric values in our APIs. The generation currently removes those aspects form the generated TypeScript APIs. But wouldn’t it make sense to keep them for documentation purposes, even if the constraints can’t be ensured technically? Using some basic type definitions?
The default constructor has two arguments (ID and mSettings) both are optional
which makes the scenario of only passing mSettings
detected as a false error.
new Page({/* ... mSettings ... */})
Examples:
"type": "[ 'Array' ].<sap.ui.core.Control>"
In JSDocs this should be either:
What is the cause of this divergence from the standard?
This results in many signatures not translated to "any", e.g:
Hello,
I was eager trying to test the typescript support.
As I depend on 1.71.* I tried with npm i @sapui5/[email protected]
and a tsconfig.json including
...
"paths": {
"sap/*": [
"./node_modules/@sapui5/ts-types/index.d.ts",
],
...
}
...
However when I try compiling via tsc
I receive:
% tsc
node_modules/@sapui5/ts-types/types/sap.uxap.d.ts:1178:12 - error TS1138: Parameter declaration expected.
1178 mParameter,: any,
node_modules/@sapui5/ts-types/types/sap.uxap.d.ts:1182:7 - error TS1138: Parameter declaration expected.
1182 sMode
@bd82 shared some infos in #215 which might be an explanation to this.
What's your take on this?
Are you looking for such feedback in order to track (possible?) human errors (hopefully not on my side 😄)?
Best,
Martin
The reasoning for this that the d.ts files are very large, sometimes they cannot be
diffed on diff view tools, and the performance of editing and "playing" with these files is sub-par.
This is hopefully an easy win to help development processes and momentum.
It should not affect functional flows.
Sub Tasks:
Currently all the SAP OpenUI5 libraries signatures are generated in a single monolith build
which accepts as input a set of api.json files.
The objective is to refactor the dts-generator package so:
Each library's signatures could be built individually.
Such a capability is needed:
Potential issues to overcome:
The directives are provided as hard-coded data inside the dts-generator.
These should be externalized.
Dependencies to other libraries (api.json files needed as inputs).
Potential Cyclic dependencies in ui5 libraries signatures.
It should be released by UI5 team build just like @ui5/ts-types
I currently cannot use demo-ts
.
Here are the steps to reproduce the issue:
git cone https://github.com/SAP/ui5-typescript.git
cd ui5-typescript
yarn
cd demos/demo-ts
yarn
tsc
Result:
[...]
../../node_modules/@sapui5/ts-types/types/sap.ui.unified.d.ts:14348:7 - error TS1109: Expression expected.
14348 sIcon=?: sap.ui.core.URI
~
../../node_modules/@sapui5/ts-types/types/sap.ui.unified.d.ts:14348:8 - error TS1109: Expression expected.
14348 sIcon=?: sap.ui.core.URI
~
Found 160 errors.
The same error appears when I use @sapui5/ts-types
in my own project.
@nlunets could you please share your POC? Thanks 😄
Implementing #111 will remove the existing snapshot tests.
We will need new ones, perhaps for the whole dist layer?
Currently, our enums are transformed to standard (integer) enums in TypeScript. Semantically, this is not correct. Our enums are string enums and I guess they should be represented as such in TypeScript. For code completion, I don’t see an issue with representing them as standard enums as the values don’t play a role. But if the type script interfaces are used for other purposes (validation?), this might cause unexpected errors.
We currently Filter it out.
It seems like a bug in the contents of it's API.json but this needs to be investigated in depth.
In UI5, classes can have namespaces, classes, enums, interfaces or typedefs as static children.
Examples:
The dts-generator currently ignores such children. It assumes, that only namespaces can contain namespaces, classes etc. When such types are referenced in signatures, they are reported as unresolved dotted type names and replaced with type any
.
According to the following stackoverflow question, it should be possible to represent the class as both, a class
and a namespace
in such cases. All nested namespaces, classes, enums etc. should go into the namespace
declaration, all instance methods and fields as well as simple static members (functions, fields) should go into the class
definition.
I tried the following in VS code (patching the sap.ui.core.d.ts) and it worked for me
namespace Popup {
enum Dock { ... }
}
class Popup {
open()
close()
}
We need to investigate how to model this in a d.ts file.
Perhaps expose as a specially named namespace?
declare namespace modules {
namespace sap {
namespace base {
// ....
}
}
}
sap.ui.define(/* ... */,
/**
* @param {modules.sap.base.bamba.A} A
/*
function(A,b,c) {
})
UI5 provides several ways to derive new simple types from built-in types.
TypeScript
string enums. They usually have a global name and that name denotes both, the type as well as the object that contains the enum values.TypeScript
, is trivial, too.string
are harder to map. Their names have a two-fold meaning:
sap.ui.base.DataType
. It will be used by the UI5 runtime to check whether a given value (string) matches the type's constraints (pattern).type
of control properties. New values for the property are then checked by the runtime against the type's constraints. Similarly, the type name can be used in JSDoc for method or event parameter types or method return types.For the TS type declarations, the focus IMO should be on the type name aspect. Currently, the dts-generator maps those types to interfaces, but a mapping to type aliases seems to be more appropriate to me. None of the suitable string values will implement the interface.
Example for sap.ui.core.CSSSize
:
type CSSSize = string
The necessary information can be found in the api.json
{
"kind": "namespace",
"name": "sap.ui.core.CSSSize", // alias name
"visibility": "public",
"ui5-metadata": {
"stereotype": "datatype", // indicator for the data type case
"basetype": "string", // base type to be aliased
"pattern": "^(auto|inherit|[-+]? ... )$"
}
}
As the constraints (pattern) cannot be expressed in TypeScript
, adding the documentation to the alias seems quite important to me. Currently, the interfaces for types come without any documentation.
Hi,
it would be great if for functions like byId
, getModel
, etc. a generic parameter would be added.
Example byId
returns sap.ui.core.Element
. If this element happens to be a sap.m.Input
it is currently not possbile to do something like view.byId("input").setValue("text")
. This will return an error setValue does not exist on type Element
.
It would be better if I could write view.byId<sap.m.Input>("input").setValue("text")
.
This should be added for all functions where the implementation is in a base class and where different element types are returned.
Thank you!
We are only using a very naive parsing of the complex JSDocs types (e.g union types).
We probably need to use A JSDoc parser such as Doctorine and transform the result
to our own AST.
Since a few releases, UI5's api.json
files can contain an optional flag for interface methods.
The dts-generator should read this flag and generate interface methods that have optional:true
with a trailing question mark (the TypeScript
notation for an optional interface method):
An api.json
of
{
"kind": "interface",
"name": "sap.ui.core.IFormContent",
"methods": [
{
"name": "getFormDoNotAdjustWidth",
"visibility": "public",
"optional": true,
"returnValue": {
"type": "boolean",
}
}
]
}
should result in a method like
interface IFormContent {
getFormDoNotAdjustWidth? ():boolean
}
I don't work with UI5 projects anymore, but I had a UI5 .d.ts generator once when openui5 was at version 1.48. I don't know how the docs are today, but I have some idea of the size of the trouble that you have here...
There are a lot of incorrectly documented details in the docs, and two ways to deal with these mistakes:
The first option is the best, but if you have to use the second, I have a list in my generator of the errors that I had to workaround when I was using my generator:
This last type of error was the hardest one to deal with, I had to generate a method overload option like (...args: any[]) => any
in the derived type to avoid compiler erros.
I don't have time to contribute to this project because I'm not working with UI5 anymore, but if you want to take a look at my previous work on this same subject, these are my repos:
Definitions in .d.ts
:
Generator used to generate the .d.ts
definitions: https://github.com/lmcarreiro/ui5ts/tree/master/src/generator
npm package to use at runtime: https://github.com/lmcarreiro/ui5ts
example project using it: https://github.com/lmcarreiro/ui5-typescript-example
The API.json files sometimes include example code snippets,
Perhaps these can be added to the JSDocs comments in the d.ts files?
As an example, getPath
should be available as a member method of ODataListBinding, since it is being inherited sap.ui.model.Binding
However, typescript raises the following error:
Property 'getPath' does not exist on type 'ODataListBinding'.
Hi,
I wanted to try out TypeScript and UI5 but so far was not able to compile my projects due to 76 type errors of the @sapui5/ts-types module. Thought the problem is on my end, but so far it seems that types inside the @sapui5/ts-types are wrong? I tested with @sapui5/ts-types versions 1.84.4 (76 errors), 1.85.2 (80 errors) and 1.78.17 (2 errors). I didn't test more versions, but it seems the tests are never quite run before publishing the modules?
Even if I run the test
script of node_modules/@sapui5/ts-types
module, I get the same errors: Can somebody tell me what's up? Do I need more dependencies or are the type definition files really that buggy? Is there a types version which work?
Cheers
> @sapui5/[email protected] test \node_modules\@sapui5\ts-types
> tsc
types/sap.ca.ui.d.ts:5419:23 - error TS2304: Cannot find name 'FileSize'.
5419 oValue: FileSize
~~~~~~~~
types/sap.f.d.ts:11720:7 - error TS2416: Property 'getGridLayoutConfiguration' in type 'GridList' is not assignable to the same property in base type 'IGridConfigurable'.
Type 'undefined' is not assignable to type '() => GridLayoutBase'.
11720 getGridLayoutConfiguration: undefined;
~~~~~~~~~~~~~~~~~~~~~~~~~~
types/sap.gantt.d.ts:4849:21 - error TS2430: Interface '$RelationshipSettings' incorrectly extends interface '$PathSettings'.
Types of property 'selectedShape' are incompatible.
Type 'SelectedRelationship | undefined' is not assignable to type 'SelectedShape | undefined'.
Type 'SelectedRelationship' is missing the following properties from type 'SelectedShape': getHeight, setHeight
4849 interface $RelationshipSettings
~~~~~~~~~~~~~~~~~~~~~
types/sap.gantt.d.ts:17630:34 - error TS2724: 'sap.gantt.simple' has no exported member named '$BaseDiamondSettings'. Did you mean '$AdhocDiamondSettings'?
17630 extends sap.gantt.simple.$BaseDiamondSettings {
~~~~~~~~~~~~~~~~~~~~
types/sap.m.d.ts:25507:11 - error TS2559: Type 'Button' has no properties in common with type 'IFormContent'.
25507 class Button extends sap.ui.core.Control
~~~~~~
types/sap.m.d.ts:26829:11 - error TS2559: Type 'CheckBox' has no properties in common with type 'IFormContent'.
26829 class CheckBox extends sap.ui.core.Control
~~~~~~~~
types/sap.m.d.ts:40654:11 - error TS2559: Type 'Image' has no properties in common with type 'IFormContent'.
40654 class Image extends sap.ui.core.Control
........
types/sap.viz.d.ts:36:36 - error TS2694: Namespace 'sap.viz.ui5.api.env' has no exported member 'Format'.
36 ): sap.viz.ui5.api.env.Format;
~~~~~~
Found 76 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @sapui5/[email protected] test: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @sapui5/[email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Hey Guys,
please consider to provide an official babel plugin. There is already a really good working way with typescript using the following babel plugin:
https://github.com/r-murphy/babel-plugin-transform-modules-ui5/blob/master/README.md
It can be combined with the JSX plugin (https://github.com/serban-petrescu/ui5-jsx-rm).
This makes UI5-devs very happy ;)
My pipeline works with all VS-Code features which makes programming UI5 much more easy and productive.
Bye.
I'm trying to use the dts-generator
to generate types for version 1.52.27 of SAPUI5. Definition file generation seems to be working in general, but every class ends up with no methods. I debugged the code and ended up in this line.
It seems like the removeBadMethods
is removing every method because it's calling lodash's include with the wrong parameter order.
It should be (collection, value)
, instead of (value, collection)
as stated in lodash docs.
I believe the fix for the issue is out in 3.7
It is really heartwarming seeing SAP eventually providing a binding for TS.
This project looks really promising.
First thing emerging from a quick test: optional function/members parameters should be marked as such:
i.e.:
in sap.m.NavContainer the only needed parameter is pageId.
Keep on with this nice code!
--R
Hi,
Is there a type script support in Sap web iIDE full stack? Can you give me any details if it is available.
Tapishnu
This seems deprecated, maybe we should not bother?
Hi team,
I understand that this is a beta project but is it planned to release in the near future? Or is there a roadmap that I can refer to?
I was creating a generation script based on this example on ts-types, but I didn't understand how to get the dependencies for each library. The OpenUI5 ones are hardcoded in the file, but how did you get this information? Do you have a script that extracts this from the api.json
files?
Initial implementation can log to console.
ui5-typescript/packages/dts-generator/lib/phases/ast-fixer.js
Lines 397 to 401 in 6638b73
The reporting / logging should probably be implemented as a new "phase"
Probably before the AST fixing phase:
ui5-typescript/packages/dts-generator/lib/api.js
Lines 35 to 38 in 6638b73
Latest version number of @openui5/ts-types when running npm outdated
still returns 1.60.0
But the current version is 1.65.1
Please update version number in package.json
with each new version of sub package ts-types
.
sap.m.URLHelper.redirect(sUrl)
When using the URLHelper
, which exists as a global on the sap.m
library, typescript shows an error message:
Property 'URLHelper' does not exist on type 'typeof m'.
In general this happens because the oClassInfo
parameter is using the generic object
type
which does not provide any type info on the members.
It is possible to declare a more specific type for oClassInfo
:
oClassInfo?: Record<string, (this:sap.ui.core.mvc.Controller, ...args: any[]) => any>
But would this suffice?
This would allow us to implement more specific tests for our output signature files
rather than just a naive test that it compiles successfully.
There is an error in the creation of the API.json file for sap.ui.core.
This means the d.ts signatures cannot be generated for 1.65.1
Log: for the command:
Ui5 build jsdoc --all
CWD: src/testsuite
info builder:builder library sap.ui.core 🔨 (1/3) Running task generateJsdoc...
WARNING: The @Private tag does not permit a value; the value will be ignored. Fi
le: ManagedObjectModel.js, line: 444
WARNING: The @Private tag does not permit a value; the value will be ignored. Fi
le: ManagedObjectModel.js, line: 453
C:\workspace\ui5-typescript\node_modules@ui5\builder\lib\processors\jsdoc\lib\u
i5\template\publish.js:1643
mContributors[$.memberof].items.push($);
^
TypeError: Cannot read property 'items' of undefined
at C:\workspace\ui5-typescript\node_modules@ui5\builder\lib\processors\jsdo
c\lib\ui5\template\publish.js:1643:30
at Array.forEach ()
at groupByContributors (C:\workspace\ui5-typescript\node_modules@ui5\builde
r\lib\processors\jsdoc\lib\ui5\template\publish.js:1638:19)
at childrenOfKind (C:\workspace\ui5-typescript\node_modules@ui5\builder\lib
\processors\jsdoc\lib\ui5\template\publish.js:1615:21)
at createAPIJSON4Symbol (C:\workspace\ui5-typescript\node_modules@ui5\build
er\lib\processors\jsdoc\lib\ui5\template\publish.js:2958:20)
at C:\workspace\ui5-typescript\node_modules@ui5\builder\lib\processors\jsdo
c\lib\ui5\template\publish.js:2178:21
at Array.forEach ()
at createAPIJSON (C:\workspace\ui5-typescript\node_modules@ui5\builder\lib
processors\jsdoc\lib\ui5\template\publish.js:2176:37)
at Object.processor (C:\workspace\ui5-typescript\node_modules@ui5\builder\l
ib\processors\jsdoc\lib\ui5\template\publish.js:491:5)
at Object.publish (C:\workspace\ui5-typescript\node_modules@ui5\builder\lib
\processors\jsdoc\lib\ui5\template\publish.js:618:42)
at Object.module.exports.cli.generateDocs (C:\workspace\ui5-typescript\node_
modules\jsdoc\cli.js:441:39)
at Object.module.exports.cli.processParseResults (C:\workspace\ui5-typescrip
t\node_modules\jsdoc\cli.js:392:24)
at module.exports.cli.main (C:\workspace\ui5-typescript\node_modules\jsdoc\c
li.js:235:18)
at Object.module.exports.cli.runCommand (C:\workspace\ui5-typescript\node_mo
dules\jsdoc\cli.js:186:9)
at C:\workspace\ui5-typescript\node_modules\jsdoc\jsdoc.js:92:9
at Object. (C:\workspace\ui5-typescript\node_modules\jsdoc\jsdoc.
js:93:3)
info builder:builder library sap.ui.core 🔨 (2/3) Running task executeJsdocSdkTr
ansformation...
info builder:tasks:jsdoc:executeJsdocSdkTransformation Failed to locate api.json
resource for project sap.ui.core. Skipping SDK Transformation...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.