Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In TypeScript, you can use the same version of setTimeout for Node and Window environment. The difference lies in the implementation of the function in each environment.

In Node, the implementation of the setTimeout function is based on the Node event loop and uses a different API than the Window implementation. However, TypeScript provides a compatible API for both environments.

So, you can use the following code for both environments:

setTimeout(() => {
  // your code here
}, delay); 

Note that you will need to import Node's Timer type in your Node project:

import { setTimeout } from  'timers'; 

In a Window environment, the implementation of the setTimeout function will be provided by the browser's JavaScript engine.