Sync Over Async (ARCH3023)
Key typescript.async.sync-over-async · Severity error · Category async
Blocking on an asynchronous operation from a synchronous context risks deadlock, starves the thread pool, and defeats the entire purpose of async.
Incorrect
Section titled “Incorrect”import { execSync } from "child_process";
function readConfig(): string { // synchronous call blocks the event loop return execSync("cat config.json").toString();}Correct
Section titled “Correct”import { readFile } from "fs/promises";
async function readConfig(): Promise<string> { return await readFile("config.json", "utf8");}Use the asynchronous counterpart of the blocking API and await the call instead of blocking.