Starting a new TypeScript project

I am putting this here for myself. I don’t want to have to search for this anymore. I do it every time I start a new TypeScript project, but I do it so rarely I always need to look it up.

First things first in the project folder.

# install typescript
npm i typescript --save-dev

# initialize the typescript project
npx tsc --init

Next, change these compiler options in tsconfig.json.

{
  "target": "es2017",  // supports async
  "outDir": "./dist",
}

Ensure the following are in package.json.

  "scripts": {
    "build": "tsc",
    "run": "tsc && node dist/index.js"
  }

Create the first code file.

mkdir src
touch ./src/index.ts

And Bob’s your uncle.

Now run your project.

Proudly powered by WordPress | Theme: Code Blog by Crimson Themes.