Event Loop
The event loop is the JavaScript runtime's scheduler: call stack, then microtasks (promise jobs), then macrotasks (timers, I/O). TypeScript does not replace it. Types describe callbacks; they do not change when those callbacks run.
Detailed Explanation
TypeScript compiles to JavaScript. The compiled file is scheduled by the same event loop as any other JS file. Promise.then, queueMicrotask, setTimeout, DOM events, and async/await continuation all run when the host says so. A type annotation cannot move a function from a macrotask to a microtask, and it cannot make two awaits concurrent.
What types do is describe the functions you hand to the loop:
setTimeout(fn, 0)—fnis() => voidinlib.dom/@types/node. Iffnreturns a promise, that promise is not awaited by the timer. The typevoidis why a returning async function is still accepted (a promise is discarded). Floating promises are a logic bug the typevoidpermits on purpose. Lint (@typescript-eslint/no-floating-promises) is the usual extra check.addEventListener("click", handler)—handleris typed as(ev: MouseEvent) => void. The event object type comes from the event name map, which is whyclickis notCustomEvent. See event types.process.nextTick/queueMicrotask— callbacks are() => voidagain.
async functions scheduled by the loop still return Promise<T>. Nothing in the type tells you whether they will run this turn or next. Awaited<T> unwraps the value, not the turn.
If you need to type "this runs after I/O," you still write a function that returns Promise<T> and document the side effect. There is no type AfterIO<T>. Some codebases brand a promise (type NextTick<T> = Promise<T> & { __when: "nextTick" }) to stop mixing with an already-resolved promise. That is a convention, not a runtime guarantee.
When people say "TypeScript changed my event loop," they usually mean one of three things: target downleveled async to generator helpers (extra microtasks on old emit), a types package typed a callback as void so a floating promise was ignored, or esModuleInterop helpers added a tick they noticed in a test. Check emit and the callback's return type.
For the actual queue order, diagrams, and setTimeout vs Promise.resolve demos, see the JavaScript event-loop page. Keep this page pointed at typing the callbacks you enqueue.
Code Examples
1. Timer callbacks are void — async work is not awaited.
// 1. Timer callbacks are void — async work is not awaited.
function schedule(fn: () => void): void {
setTimeout(fn, 0);
}
schedule(() => {
console.log("tick");
});
schedule(async () => {
await Promise.resolve();
console.log("also a tick, but the promise is floating");
});2. The type of an event callback comes from the event name.
// 2. The type of an event callback comes from the event name.
function onClick(ev: MouseEvent): void {
console.log(ev.clientX);
}
document.addEventListener("click", onClick);3. Types do not reorder awaits.
// 3. Types do not reorder awaits.
async function order(): Promise<string> {
const a = await Promise.resolve("first");
const b = await Promise.resolve("second");
return `${a} ${b}`;
}Common Gotchas
`() => Promise<void>` is assignable to `() => void`
the caller will not await you. That is how floating promises get into timers and listeners.
Do not invent a type that claims to change scheduling
`Promise<T>` is already "later." Extra brands are documentation.
Old `target` downlevels `async` and can add extra ticks
if tests depend on microtask count, raise `target` or test behavior, not tick counts.
The JS event-loop page is the behavior reference
this page will not re-list macrotask vs microtask order.