diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-08-31 17:54:22 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-01 07:49:19 +0000 |
commit | f435267a16588891429124049b3b036c5c755270 (patch) | |
tree | 92636f171f1d2be3624e6a35575e3ca63575c196 | |
parent | 743c09bab0e4e1e83d64c50939957746e5a1260e (diff) | |
download | qtdoc-f435267a16588891429124049b3b036c5c755270.tar.gz |
qmlapp/codingconventions: Recommend using type annotations
Task-number: QTBUG-96150
Change-Id: Iaeaff2558935ca1008fb19416ec4852b6ee51549
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 5d32ab418948b9a595cb811c70fe308297ae5d0f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | doc/snippets/qmlapp/codingconventions/javascript.qml | 2 | ||||
-rw-r--r-- | doc/src/qmlapp/codingconventions.qdoc | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/doc/snippets/qmlapp/codingconventions/javascript.qml b/doc/snippets/qmlapp/codingconventions/javascript.qml index f2952f49..264ae6bf 100644 --- a/doc/snippets/qmlapp/codingconventions/javascript.qml +++ b/doc/snippets/qmlapp/codingconventions/javascript.qml @@ -68,7 +68,7 @@ Rectangle { //![1] //![2] -function calculateWidth(object) +function calculateWidth(object : Item) : double { var w = object.width / 3 // ... diff --git a/doc/src/qmlapp/codingconventions.qdoc b/doc/src/qmlapp/codingconventions.qdoc index e17c4828..6fc7b67d 100644 --- a/doc/src/qmlapp/codingconventions.qdoc +++ b/doc/src/qmlapp/codingconventions.qdoc @@ -102,6 +102,10 @@ If the script is more than a couple of lines long or can be used by different ob \snippet qmlapp/codingconventions/javascript.qml 2 +Also note that is recommended to add type annotations to your function in order +to more easily reason about and refactor your application since both parameter +and return types are immediately visible from the function signature. + For long scripts, we will put the functions in their own JavaScript file and import it like this: \snippet qmlapp/codingconventions/javascript-imports.qml 0 |