Under Review
over 2 years ago

SDK 4.1.6: makeWebRequest's responseCallback signature is missing PersistedContent.Iterator as allowed type for "data" arg

Issue

The new compiler complains in strict type checking mode for functionally working code which cannot be fixed due to missing types in "makeWebRequest" "responseCallback" signature.

Description

I am using "makeWebRequest" to download course files to the device. In the code for the "responseCallback" method, I'm testing the validity of the "data" argument with an "instanceof" check to see if it is a PersistedContent.Iterator object, which indicates that a course has been downloaded, which I can then access using "next". This is working well functionally, but with strict type checking, the new compiler now complains about this: "Type 'PolyType<Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String>' is not an instance of '$.Toybox.PersistedContent.Iterator'.

public function callback(response as Number, download as Dictionary or String or Null) as Void {
// other code omitted
if (download instanceof PersistedContent.Iterator)) { // compiler complains about this line

Currently it is impossible to resolve this issue, as the signature of "makeWebRequest" forces me to declare the argument as "Dictionary or String or Null".

The missing type PersistentContent.Iterator seems to be an oversight as I know from working code that this will be returned when downloading a course and it is also stated in the official documentation.

Software

CIQ SDK 4.1.6

VSC 1.73.1

VSC Extension 1.0.7

OS: Linux (Kubuntu 22.04.1)

Fix

Add "PersistentContent.Iterator" to the PolyType signature of responseCallback's "data" argument like so:

responseCallback as
Lang.Method(responseCode as Lang.Number, data as Lang.Dictionary or Lang.String or PersistentContent.Iterator or Null) as Void or
Lang.Method(responseCode as Lang.Number, data as Lang.Dictionary or Lang.String or PersistentContent.Iterator or Null, context as Lang.Object) as Void