haxetink / tink_await

Haxe async/await
MIT License
58 stars 15 forks source link

Variables of type Void are not allowed #42

Closed sonygod closed 3 years ago

sonygod commented 3 years ago

js code

const puppeteer = require('puppeteer');

const devices = require('puppeteer/DeviceDescriptors');

(async () => {
  const browser = await puppeteer.launch({ headless: false, devtools: true });
  const page = await browser.newPage();

  await page.emulate(devices['iPhone X']);
  await page.goto('https://www.qikegu.com');

//   await browser.close();
})();
     /** Emulates given device metrics and user agent. This method is a shortcut for `setUserAgent` and `setViewport`.  */
  emulate(options: EmulateOptions): Promise<void>;

and haxe code

@await page.emulate(d).toSurprise();

or

@await page.emulate(d).toPromise();

will got Variables of type Void are not allowed

kevinresol commented 3 years ago

Please provide a compilable snippet.

sonygod commented 3 years ago

pp.zip

npm install puppeteer
haxe build.hxml
node Main.js

@kevinresol .here is an example package.

sonygod commented 3 years ago
package;
import puppeteer.EmulateOptions;
import Puppeteer;
import puppeteer.devices.Device;
import puppeteer.Browser;
using tink.CoreApi;
@await
class Main {
    @async 
    public static function main() {
        var browser:Browser = @await Puppeteer.launch({headless: false, devtools: true}).toPromise();

        var page=@await browser.newPage().toPromise();

    //  var d:Device={name:'iPhone X'};
        //@await  page.emulate(d).toPromise();

        @await page.setViewport({
            width: 375,
            height: 667,
            isMobile: true,
            hasTouch:true
        }).toPromise();

        @await page.goto('https://www.baidu.com').toPromise();

    }
}
kevinresol commented 3 years ago

I think you forgot to return something for your @async function

sonygod commented 3 years ago
/**
    Sets the viewport of the page.
**/
function setViewport(viewport:Viewport):js.lib.Promise<Void>;

js.lib.Promise <Void> can not use in **.toPromise();**

and the js code is

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: false, devtools: true });
  const page = await browser.newPage();

  await page.setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1');
  await page.setViewport({ width: 375, height: 812 });

  await page.goto('https://www.qikegu.com');

//   await browser.close();
})();
sonygod commented 3 years ago

I thinktoPromise() should support Promise<Void>

kevinresol commented 3 years ago

imo Void shouldn't be used as type parameter at all

sonygod commented 3 years ago

well,close this issue now.