Closed one-github closed 2 years ago
@one-github ok, got it: these four errors occur when in the tsc compiler options "strict" mode is enabled, but "strictPropertyInitialization" is not disabled.
In our sample tsconfig files, this is the case:
...
"strict": true,
"strictPropertyInitialization": false,
...
Let me check whether we can avoid requiring this setting (there are seven more such errors in @sapui5/ts-types-esm). Thanks for your patch proposal! Not all changes in UI5 can be done (because we cannot change incompatibly), but at first glance they look harmless.
Oh, and obviously you can avoid the error message for the time being by adding
"strictPropertyInitialization": false,
to your tsconfig.
On second glance, the strictPropertyInitialization
thing doesn't make any sense.
Sorry, it's the
"strictNullChecks": false,
setting which is needed to avoid the four errors.
Sorry, it's the
"strictNullChecks": false,
setting which is needed to avoid the four errors.
IMHO having activated this option is important - I want TypeScript to check my code for as many statically detectable sources of error as possible.
That's understandable and should be our goal. Fixes for the issues in Table and LightBox are on the way (as the type definitions are generated, those fixes happen in the OpenUI5 JSDoc), but the two UIArea issues are trickier. The original code shows why: the UIArea can indeed return null here (or does it even always), unlike regular controls.
/**
* Provide getBindingContext, as UIArea can be parent of an element.
*
* @returns {null} Always returns null.
*
* @protected
*/
UIArea.prototype.getBindingContext = function(){
return null;
};
/**
* Returns this <code>UIArea</code>'s id (as determined from provided RootNode).
* @return {string|null} id of this UIArea
* @public
*/
UIArea.prototype.getId = function() {
return this.oRootNode ? this.oRootNode.id : null;
};
We'll have a deeper look.
Another change fixed one of the UIArea issues: https://github.com/SAP/openui5/commit/ff2b05340eb90375c58bd5875e803e6cb19d8eae
In a further change, the d.ts generation will probably be configured to add a @ts-ignore for UIArea.getId().
Afterwards, the type definitions will be compatible with strictNullChecks:true.
Further changes will do the same for the full SAPUI5 type definitions and will make sure there are no regressions. Thanks for prompting us to improve this!
Well... I just noticed that DefinitelyTyped prevents the use of ts-ignore in d.ts files.
There is a hardcoded check in their dtslint check which our type definitions have to pass: https://github.com/microsoft/dtslint/blob/274f0d0cf64fb03765fb5f70009fe5f00b8ecf9c/src/lint.ts#L130
So I have to revert the ts-ignore for UIArea.getId() (and for the other remaining occurrence in the sap.ui.comp library in SAPUI5). I'm not sure right now how to proceed - we'll discuss it. Until we find a way out, the two issues will remain.
You could consider using // @ts-expect-error
instead.
But if you mark a code snippet with this comment and no error is detected
that in itself would cause a TSC compliation error 😢
https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-beta/#ts-expect-error-comments
As we cannot change the implementation and as we want the JSDoc documentation to be as correctly describing the behavior as possible, we decided to add a generation hint which slightly changes what is generated as type definition: UIArea.getId() is said to return type "string". This will be in effect with the 1.97 release.
There's unfortunately one more issue within OpenUI5 left, which prevents strictNullChecks. It came in before we added a check to our tests. But it was fixed here for 1.98: https://github.com/SAP/openui5/commit/5a4d90ec5b314f210c035e85212b98ceefb05d3a
@one-github With the just published version 1.98.0, full strict mode should be working fine.
See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/58429
Using the @openui5/ts-types-esm@1.93.0 with Typescript version 4.5.0-dev.20210812 there are errors with the type definitions themselves when running
tsc
:Installed packages:
tsconfig.json:
Typescript version:
The incompatible declarations can be patched so that they compile correctly: