process.versions.bun to detect whether code is running in Bun. This works in both JavaScript and TypeScript without extra type definitions.
Alternatively, check for the
Bun global, the same way you’d check for window to detect a browser.
In TypeScript, this is a type error unless
@types/bun is installed. Install it with bun add -d @types/bun.