ui5-typescript
ui5-typescript copied to clipboard
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) {
})
Maybe "import types" would be relevant?
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).
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 :)
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
The generator will get support for the generation of the ts-types-esm
with the upcoming 3.0
release.