Giter Site home page Giter Site logo

sap / ui5-typescript Goto Github PK

View Code? Open in Web Editor NEW
199.0 22.0 27.0 14.82 MB

Tooling to enable TypeScript support in SAPUI5/OpenUI5 projects

Home Page: https://sap.github.io/ui5-typescript

License: Apache License 2.0

JavaScript 5.83% TypeScript 94.17%
open-source openui5 sapui5 typescript

ui5-typescript's People

Contributors

akudev avatar bd82 avatar codeworrior avatar dependabot-preview[bot] avatar dependabot[bot] avatar flovogt avatar greenkeeper[bot] avatar m8524769 avatar mauriciolauffer avatar misappi avatar nlunets avatar petermuessig avatar randombyte avatar sapirpol avatar sebastianwolf-sap avatar sebbi08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ui5-typescript's Issues

Where do you get or how do you generate api.json files?

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 ;)

Custom Types For Integer and Float

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?

Constructor Signatures Overloading

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 ... */}) 

sap.uxap.d.ts: possible generation errors? (1.71.28)

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

Evaluate Splitting the signatures to multiple files for each library

  • Each namespace in a different file?
  • How to calculate the dependencies automatically?

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.

Define Release Management Strategy

  • Should new releases be made for patch versions of OpenUI5?
  • For which versions of OpenUI5 should releases be made?
  • Should Each release correspond to a branch or just a tag?

Granular (per library) d.ts signature generation.

Sub Tasks:

  • Ability to pass directives as arguments.
  • Move directives to be part of ts-types package rather then dts-generator.
  • Ability to pass two sets of API.json inputs, Those to generate (to file) and those only used as dependencies.
  • Ability to pass in custom logic that determines how the dependency import is implemented in the generated code.
  • Generate each library individually for @openui5/ts-types
  • Release @ui5/dts-generator to npmjs.com (blocked on npmjs permissions)

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:

  • As a pre-requisite to integrate the dts-generator into UI5 builds.
  • As a pre-requisite to expose the dts-generator as a UI5 build tool.

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.

demo-ts compilation fails

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.

String Enums representation

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.

See in playground

dts-generator ignores child namespaces/enums etc. of classes

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()
  }

Support new UI5 "Modules"

We need to investigate how to model this in a d.ts file.

  • As a TypeScript module it may not mean anything as UI5 have their own model system,
  • As a global namespace it may incorrectly expose none global APIs as modules are only usable via sap.ui.define.

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) {

})

Consider to use Type Aliases for UI5 data types

UI5 provides several ways to derive new simple types from built-in types.

  • One way are string based enums, which perfectly translate to 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.
  • Mapping UI5's Array types to TypeScript, is trivial, too.
  • But pattern-based specializations of type string are harder to map. Their names have a two-fold meaning:
    • DataType object: the global property with the same name as the type points to an object which is an instance of 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 name: the same name can be used as 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.

Add generics for better chaining of calls

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!

Complex JSDocs Types Parsing

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.

dts-generator should handle optional flag for interface methods

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
}

About others incorrectly documented info in the official docs

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:

  1. Fix the docs in the official repo
  2. Setup the generator to workaround it

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

Add "example" snippets to JSDocs

The API.json files sometimes include example code snippets,
Perhaps these can be added to the JSDocs comments in the d.ts files?

Types missing for some borrowed methods

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'.

Types within @sapui5/ts-types are invalid

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?

Please check working TS alternatives / babel plugin

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.

dts-generator generating classes with no methods

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.

image

It should be (collection, value), instead of (value, collection) as stated in lodash docs.

Heuristic to detect incorrectly documented Optional member parameters

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

Planned release date

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?

How to get dependencies from a library?

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?

image

Log required parameters which are suspected to actually be optional.

Update version number

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.

URLHelper missing in sap.m 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'.

Incorrect "this" type inside `oClassInfo` parameter of `extend` method

image

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?

Release Signatures for @openui5 version 1.65.1

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...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.