Skip to content

Instantly share code, notes, and snippets.

@mtfrsantos
Last active July 18, 2023 12:58
Show Gist options
  • Save mtfrsantos/4c90fb47046e509c46c2f7c3b771964e to your computer and use it in GitHub Desktop.
Save mtfrsantos/4c90fb47046e509c46c2f7c3b771964e to your computer and use it in GitHub Desktop.
New TypeScript project steps

New TypeScript project steps

Check node version

node --version

Install latest node version

nvm install node

Generate package.json

npm init -y

Install yarn

npm install -g yarn

Install TypeScript and Jest

yarn add typescript jest @types/jest ts-node ts-jest

Initialize TypeScript

npx tsc --init

Change tsconfig.json content to this

{
    "compilerOptions": {
        "incremental": true,
        "target": "es2016",
        "module": "commonjs",
        "outDir": "./dist",
        "strict": true,
        "esModuleInterop": true
    },
    "include": [
        "src",
        "test"
    ]
}

Create src and test directories

mkdir src test

Initialize jest config

npx ts-jest config:init

Add scripts in package.json

"scripts": {
    "main": "tsc && node ./dist/main",
    "test": "tsc && jest ./dist/test"
  },

Run without ts-node

npm run main

Run with ts-node

npx ts-node src/main.ts

Run test without ts-jest

npm run test

Run test with ts-jest

npx jest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment