Skip to content

mitchallen/typescript-101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typescript-101

Example TypeScript project

Reference

Usage

npm start

Cheat Sheet

  • Init project
npm init -y
  • Install ts locally
npm install typescript --save-dev
  • Make source folder
mkdir src
  • Add script

Add this script to package.json:

"tsc": "tsc",
  • Initialize tsc (gen tsconfig.json)
npm run tsc -- --init
  • Edit tsconfig.json (uncomment and update values and save):
  "compilerOptions": {
    "target": "ES6",
    "module": "CommonJS",
    "rootDir": "./src",
    "outDir": "./dist", 
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
  • create a file
touch src/app.ts
  • update main in package.json
"main": "./dist/app.js",
  • add build script command
"build": "tsc",
  • run build
npm run build

ls -ls dist

cat dist/app.js 
  • add a start script command and save the file
"start": "node dist/app.js",
  • run the start script
npm start
  • add a prestart script command to build first
"scripts": {
  "prestart": "npm run build",
  • add a clean command:
"clean": "rm -rf dist",
  • run the clean command
npm run clean

About

Example TypeScript app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published