First a bug
1) Some namespacing/alias issue with has
using Toybox.WatchUi as Ui; // ... code here // eventually if (Ui has :TextPicker) { // do things } // Yields error: ERROR: fenix6xpro: file:lineno: Undefined symbol ':Ui' detected. // Needs to change to WatchUi and/or Toybox.WatchUi to not error.
Secondly a ... You may file this as a bug or a feature, because I'm torn between what it is. I just know it is a tad-bit annoying.
// Let's assume the following code: function refresh() { var ids = $.profiles.getIds(); for (var i =0; i< ids.size(); i++) { var shim = $.profiles.getShim(ids[i]); upsertProfileShim(shim); } if ($.profileDeletedId != null) { M2.deleteItem(self, $.profileDeletedId); } } // and the following code for the profile getIds() method function getIds() as Array<String> { var array = [] as Array<String>; array = self.profiles.keys(); return array; } // equally frustrating, of not more class Bar { var thing as Array<Numeric> function initialize() { thing = [ 1, 2 ]; // yields and warnings // must be changed to thing = [ 1, 2 ] as Array<Numeric>; // I just told you what it is } }
It's insanely annoying that even when we sprinkle the code in getIds() with typing information that the callers need to do the very same thing on a container. We don't have to do this for Strings or other type of objects.
class Foo { function initialize() { } function foo() as Foo { return new Foo(); } } // This works fine, we don't need to tell anyone we are getting an object Foo. var f = new Foo(); var b = f.foo(); var c = b.foo();
3) I came across one more thing:
Toybox.Application.Storage as st; // .. st.setValue("profiles", {}); // error // Work around it var d = { 0 => 1 }; d.remove(0); st.setValue("profiles", d); // Or set this piece of weirdly looking code st.setValue("profiles", {} as Lang.Dictionary<String, Null>);
But even when you want to enforce this, please, move the warning to gradual (level 2). If you want to pedantic, be it in informative.
I want type checking 1 for checking input params at functions, but the container warnings are a bit too much.