I have a setTimeout callback but when i put this inside another function, I'm getting an error with 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.
If i remove the outer wrapping delayedSnapshot
it will compile fine however.
I found something here on what ambient means but it doesn't seem relevant.
http://www.typescriptlang.org/Handbook#modules-working-with-other-javascript-libraries
can someone explain how I stop this error from happening but still keep my wrapper to control the callback firing or not?
Therefore, don't use strings for the delay value but instead always use numbers: setTimeout () is an asynchronous function, meaning that the timer function will not pause execution of other functions in the functions stack. In other words, you cannot use setTimeout () to create a "pause" before the next function in the function stack fires.
When you pass a method to setTimeout (), it will be invoked with a this value that may differ from your expectation. The general issue is explained in detail in the JavaScript reference . Code executed by setTimeout () is called from an execution context separate from the function from which setTimeout was called.
The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds. Tip: 1000 ms = 1 second. Tip: The function is only executed once.
In other words, you cannot use setTimeout () to create a "pause" before the next function in the function stack fires. Notice that the first function does not create a 5-second "pause" before calling the second function. Instead, the first function is called, but waits 5 seconds to execute.
Change the function name from delayedSnapshot()
to something else.
There seems to be a delayedSnapshot()
method defined/declared somewhere else, which is being overloaded here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With