ui5-typescript icon indicating copy to clipboard operation
ui5-typescript copied to clipboard

Support new UI5 "Modules"

Open bd82 opened this issue 5 years ago • 5 comments

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

})

bd82 avatar Apr 29 '19 07:04 bd82

Maybe "import types" would be relevant? alt text

bd82 avatar Apr 29 '19 07:04 bd82

I rather would model them as real typescript modules:

declare module "sap/base/i18n/ResourceBundle" {
    export default class ResourceBundle {
        getText(key:string): string
        static create() : ResourceBundle
    }
}

This allows to refer to them in signatures

declare namespace sap {
  ...
    class ResourceModel extends sap.ui.model.Model {
      constructor( 
          bundle? : typeof import("sap/base/i18n/ResourceBundle") | any
      )
}

and it preserves the scoping of modules (no global names, no naming conflicts with other names).

codeworrior avatar Nov 10 '19 22:11 codeworrior

Technically why would you even need the namespace in a modern UI5 development ? People don't usually refers to the namespace value in modern ui5 (expect for getting the sap.ui.getCore()) so exposing a namespace may lead to bad practice compared to using module definition :)

nlunets avatar Mar 10 '20 12:03 nlunets

Yes, we could possibly avoid exporting global namespaces and only export modules maybe we do not need to support super legacy global style UI5 code and only support sap.ui.define style or other module systems

bd82 avatar Mar 10 '20 13:03 bd82

The generator will get support for the generation of the ts-types-esm with the upcoming 3.0 release.

petermuessig avatar Nov 28 '21 15:11 petermuessig