typescript to javascript code example
Example 1: install typescript
Don't forget to use the dev flag!!!
Yarn:
yarn global add --dev typescript
NPM:
npm install -g --save-dev typescript
Example 2: how to run typescript file
npx ts-node src/foo.ts
Example 3: how to compile ts in cmd
"scripts": {
"clean": "rimraf dist",
"start": "npm-run-all clean --parallel watch:build watch:server --print-label",
"watch:build": "tsc --watch",
"watch:server": "nodemon './dist/index.js' --watch './dist'"
}
Example 4: convert javascript to typescript
1. Add tsconfig.json file to project
2. Integrate with a build tool
3. Change all .js files to .ts files
4. Check for any errors