process.versions.bun. This works in both JavaScript and TypeScript without requiring any additional type definitions.
Alternatively, you can check for the existence of the
Bun global. This is similar to how you’d check for the existence of the window variable to detect when code is being executed in a browser.
This approach will result in a type error in TypeScript unless
@types/bun is installed. You can install it with bun add -d @types/bun.