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
  • Had the same issue for my code. What solved the problem was introducing types to the http handling callback function to this:

    ```

    function onReceive(
    responseCode as Toybox.Lang.Number,
    data as Toybox.Lang.Dictionary
    ) as Void {
    ```
  • My point still stands: you can either turn off type checking or attempt to fix type check errors, but not both at the same time.

    Also, you previously suggested turning off type checking in the extension settings, and now you are saying leave the default type checking level in the extension settings but change the the level in monkey.jungle lol.

    > By turning off type checking for now, you can see if any differences occur for your app starting with 4.1.6.

    Turning off type checking doesn't actually tell you if any differences occur for your app starting with 4.1.6 lol. Turning off type checking actually hides those differences (assuming all the differences are due to type checking - ofc if there's any differences unrelated to type checking, none of this advice applies to that at all.)

    > Then try the lowest level of type checking and see what you see.  Once that's ok, try the middle level of type checking, then the strict level

    Right, so actually, *turning on type checking* is what you are suggesting to do in order to fix type check errors....

  • By turning off type checking for now, you can see if any differences occur for your app starting with 4.1.6.  Then try the lowest level of type checking and see what you see.  Once that's ok, try the middle level of type checking, then the strict level

    if you add

    project.typecheck=0

    to your monkey.jungle file, you change 0 to 1, 1 to 2. and 2 to 3 to go through the levels and only for that specific project.  You want the setting for type checking to be "default" in the VS Code extension settings.

  • Thank you and . Now everything is clear to me. First I turn off the type checking and later I fix any "errors".

  • > 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.)