I saw many examples of timer with Promise for JavaScript. Most of them are too complicated, but I suppose, it could be implemented more simply. However, I need the solution for TypeScript in "strict": true
mode with all annotations.
I tried to do it until below code:
import Timeout = NodeJS.Timeout;
let testTimeout : Timeout;
const DELAY: number = 3000;
testTimeout = (): Promise<void> => (
new Promise<void>( (resolve): void => {
setTimeout(resolve, DELAY);
})
);
testTimeout = testTimeout().then( () => {
console.log('done');
});
clearTimeout(testTimeout);
It has errors:
TS2739: Type '() => Promise<void>' is missing the following properties from type 'Timeout': ref, refresh, unref
TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Timeout' has no compatible call signatures.
I suppose, I do something wrong.