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
.
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}
Ensure the following are in package.json
.
"scripts": {
"build": "tsc",
"dev": "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.