Acknowledged

Visual Studio Code and makeWebRequest and SDK 4.1.6+

Hi,
this does not work with SDK 4.1.6 and later in Visual Studio Code:
Communications.makeWebRequest("https://api.openweathermap.org/data/2.5/weather", params, options, method(:onReceiveWeather));
Error:
Invalid '$.Toybox.Lang.Method(responseCode as Any, data as Any) as Any'
passed as parameter 4 of type
'PolyType<(callback(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String) as Void)
or
(callback(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String, context as $.Toybox.Lang.Object) as Void)>'.
Unfortunately I have no idea what could be causing this.
Has the function been removed or changed?
Regards
Joerg
Parents
  • > try turning type checking off

    > Then you can look at why type checking is reporting an issue

    Seems to be two conflicting pieces of advice here. They can either turn off type checking or look at why it's reporting an issue, but I don't see how they can do *both*. Once you turn off type checking, it will no longer report an issue, so it seems like there would be little reason to try to resolve said issue. Even if they tried, how would they know it was resolved until they turned type checking back on?

    Anyway, from the error message itself (and reading between the lines of the OP), I would guess that onReceiveWeather() callback function that's passed to makeWebRequest() is probably defined as something like this (without type declarations):

    function onReceiveWeather(responseCode, data) {
    // ...
    }

    The error message is saying that the type checker wants the callback function's argument types and return type to be explicitly declared. e.g.

    import Toybox.Lang;
    //...

    function onReceiveWeather(responseCode as Number, data as Null or Dictionary or String) as Void {
    // ...
    }

    But yeah, for existing projects you may wish to turn off type checking. This can be done either on a global basis (User preferences) or a per-workspace basis. (So you can use the default type checking settings for new projects, if you wish.)

Comment
  • > try turning type checking off

    > Then you can look at why type checking is reporting an issue

    Seems to be two conflicting pieces of advice here. They can either turn off type checking or look at why it's reporting an issue, but I don't see how they can do *both*. Once you turn off type checking, it will no longer report an issue, so it seems like there would be little reason to try to resolve said issue. Even if they tried, how would they know it was resolved until they turned type checking back on?

    Anyway, from the error message itself (and reading between the lines of the OP), I would guess that onReceiveWeather() callback function that's passed to makeWebRequest() is probably defined as something like this (without type declarations):

    function onReceiveWeather(responseCode, data) {
    // ...
    }

    The error message is saying that the type checker wants the callback function's argument types and return type to be explicitly declared. e.g.

    import Toybox.Lang;
    //...

    function onReceiveWeather(responseCode as Number, data as Null or Dictionary or String) as Void {
    // ...
    }

    But yeah, for existing projects you may wish to turn off type checking. This can be done either on a global basis (User preferences) or a per-workspace basis. (So you can use the default type checking settings for new projects, if you wish.)

Children
No Data