Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Overload signatures must all be ambient or non-ambient" when using setTimeout in another function

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?

like image 755
dcsan Avatar asked Sep 03 '15 22:09

dcsan


People also ask

Should I use strings for the delay value of setTimeout()?

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.

What happens when you pass a method to setTimeout()?

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.

What is the use of setTimeout?

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.

Can setTimeout() be used to pause a function in a stack?

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.


1 Answers

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.

like image 196
Yash Avatar answered Oct 18 '22 12:10

Yash