[Interest] QML type hints and their problems
Ulf Hermann
ulf.hermann at qt.io
Wed Nov 3 08:45:59 CET 2021
a, Use type annotations on all JavaScript functions in QML files.
Period. It helps tooling, gives you better diagnostics from qmllint and
qmlsc, helps you understand your code better. There are no downsides.
b, In this particular case we could be more lenient, but what if that
was actually an unrelated "contains" method? Mind that you can shadow
those methods by inheriting or by mixing C++ and QML. If we get the
wrong one, we can probably still JavaScript-coerce the argument to point
and the return value to bool, but the result will be a mess and rather
hard to debug.
c, The change that introduced the containment masks,
https://codereview.qt-project.org/c/qt/qtdeclarative/+/211550 , only
intended the contains() functions to be defined in C++. Later, starting
with https://codereview.qt-project.org/c/qt/qtdeclarative/+/249400 ,
we've added type annotations for JavaScript functions. Using those you
can now define typed functions in JavaScript and they are treated the
same way as C++ functions. So, be happy that this works at all ;)
More information about the Interest
mailing list