在另一个函数中使用 setTimeout 时,“重载签名必须全部为环境或非环境”

dcs*_*san 7 overloading ambient typescript

我有一个 setTimeout 回调,但是当我把它放在另一个函数中时,我收到一个错误tsc

function delayedSnapshot() {

    setTimeout( function() {
        var filename = "/Users/dc/dump/heapdump.heapsnapshot";
        heapdump.writeSnapshot(function(err, filename) {
          console.log("dump written to", filename);
        });
        process.exit(1);

    }, 5000);

}

>> error TS2384: Overload signatures must all be ambient or non-ambient.
Run Code Online (Sandbox Code Playgroud)

但是,如果我移除外包装,delayedSnapshot它会编译得很好。我在这里找到了一些关于环境意味着什么的东西,但它似乎并不相关。

http://www.typescriptlang.org/Handbook#modules-working-with-other-javascript-libraries

有人能解释一下我如何阻止这个错误发生,但仍然保持我的包装器来控制回调触发与否?

小智 3

将函数名称更改为delayedSnapshot()其他名称。

似乎delayedSnapshot()在其他地方定义/声明了一个方法,该方法在这里被重载。