Skip to content

将minapp-generator的tsconfig.json的target调整为es2017会提示done函数找不到 #43

Open
@AlexStacker

Description

本来想调试简单一些,直接使用node的async、await,就将target调整为es2017,不用typescript的tslib,结果报done不存在了。
如果调整target为es2017的话async库的调用方式不一样,会走asyncify不传递callback

// async.js L192-211
function asyncify(func) {
    return initialParams(function (args, callback) {
        var result;
        try {
            result = func.apply(this, args);
        } catch (e) {
            return callback(e);
        }
        // if result is Promise object
        if (isObject(result) && typeof result.then === 'function') {
            result.then(function(value) {
                invokeCallback(callback, null, value);
            }, function(err) {
                invokeCallback(callback, err.message ? err : new Error(err));
            });
        } else {
            callback(null, result);
        }
    });
}

我将代码调整了一下,大佬要不要参考一下

// cmd.ts L86
let result = await new Generator(key, node, nodeUrl, nodeSource, genDir)
  .exec(res.markdown, res.promise)
  .then((str) => {
    if (!allResult) allResult = []
    if (str) allResult.push(str)
    return allResult;
  })
  //.catch((e: any) => done(e))

  if(done) {
    done(undefined, result)
  } else {
    return result;
  }

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions