cancel
Showing results for 
Search instead for 
Did you mean: 

error TS2339: Property does not exist on type

lfrey91
Participant
0 Kudos

Hi TypeScript Team,

I get 3 errors here where I think they are not errors

I am using

sap.m.IconTabHeader for .getSelectedKey

and

sap.ui.layout.VerticalLayout for .setVisible

in the console it is working

peter.muessig

do you have a quick fix for this?

bye Luis

View Entire Topic
AndreasKunz
Advisor
Advisor

Hi Luis,

the error message already indicates it: TypeScript does not find these methods on UI5Element (which stands for the sap.ui.base.Element base class of all Controls etc.).

The TypeScript compiler simply is not aware that this.byId(...) returns an IconTabHeader. It cannot know this, as the returned control type depends on the ID which you give as argument (and there is no functionality which searches the id in the XMLView and tells TypeScript what kind of control has this ID).

The solution is to cast the result of this call to the control type you know is returned:

(this.byId("idIconTabBar") as IconTabBar).getSelectedKey()

This is commonly done in the tutorial and samples linked from the central UI5 & TypeScript entry point (https://sap.github.io/ui5-typescript), so I guess it makes sense to mention this page for those who are getting here and not aware of it.

Regards

Andreas

lfrey91
Participant
0 Kudos

Great that worked!