eclipsesource / tabris-js

Create native mobile apps in JavaScript or TypeScript.
https://tabrisjs.com
BSD 3-Clause "New" or "Revised" License
1.4k stars 170 forks source link

TS 4.x+: cannot override properties of Tabris widgets #2285

Open cpetrov opened 8 months ago

cpetrov commented 8 months ago

Problem description

Widget properties like e.g. left and height are exposed as class fields in the Tabris.js typings. However, at runtime, they are actually defined as accessors.

While it was possible to define property accessors in custom widgets that override Tabris.js widget properties in TypeScript 3.x, this does not work anymore since TypeScript 4.x. Since TypeScript 4.x, it is forbidden to override class fields using accessors (makes sense, because this does not work at runtime), which prevents customizing the behavior of Tabris.js properties in custom widgets:

class CustomWidget extends Composite {
  set height(value: number) { // 'height' is defined as a property in class 'Composite<Widget<any>>', but is overridden here in 'CustomWidget' as an accessor.ts(2611)
    super.height = value;
  }
  get height() {
    return super.height;
  }
}

Expected behavior

Tabris.js properties that are accessors at runtime should be defined as accessors in the typings as well.

Environment