Bun foundations

Create and run a TypeScript project

Initialize a Bun project, inspect its files, and run TypeScript directly without a separate build step.

8 minute lesson

~~~

Let’s create the project we’ll use throughout the course.

Create a directory and initialize Bun inside it:

mkdir bun-notes
cd bun-notes
bun init --yes

bun init creates a small TypeScript project. The exact files may change as Bun evolves, but you should see package.json, tsconfig.json, and index.ts.

Replace the contents of index.ts with this:

const message: string = 'Hello from Bun'

console.log(message)

Run the file:

bun index.ts

Bun prints:

Hello from Bun

Bun transpiles TypeScript while it loads the file. We did not run tsc first, and we did not create a JavaScript copy.

Notice the word transpiles. Bun removes TypeScript syntax so the runtime can execute the program. This does not mean Bun performs a complete type check before every run.

Keep your editor’s TypeScript checks enabled. For a separate command-line type check, install TypeScript and run tsc --noEmit:

bun add --dev typescript
bunx tsc --noEmit

Running code and checking types are two different jobs. Keeping that distinction clear prevents a successful bun index.ts command from giving us false confidence about the types.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →