Typescript is simply Javascript with type checking.
You will need a few things:
VSCode - https://code.visualstudio.com
Node - https://nodejs.org/en/download
Install TypeScript using the Node Package Manager.
npm i -g typescript |
Confirm TypeScript is Installed by running the TypeScript Compiler
tsc -v |
> vi index.ts
console.log("hello-world"); |
Compile and Run
tsc ./index.ts node index.js |
We can create a TypeScript configuration using the following command:
tsc -init |
{ // Visit https://aka.ms/tsconfig to read more about this file "compilerOptions": { // File Layout // "rootDir": "./src", // "outDir": "./dist", // Environment Settings // See also https://aka.ms/tsconfig/module "module": "nodenext", "target": "esnext", "types": [], // For nodejs: // "lib": ["esnext"], // "types": ["node"], // and npm install -D @types/node // Other Outputs "sourceMap": true, "declaration": true, "declarationMap": true, // Stricter Typechecking Options "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, // Style Options // "noImplicitReturns": true, // "noImplicitOverride": true, // "noUnusedLocals": true, // "noUnusedParameters": true, // "noFallthroughCasesInSwitch": true, // "noPropertyAccessFromIndexSignature": true, // Recommended Options "strict": true, "jsx": "react-jsx", "verbatimModuleSyntax": true, "isolatedModules": true, "noUncheckedSideEffectImports": true, "moduleDetection": "force", "skipLibCheck": true, } } |
References
Reference | URL |
---|---|
TypeScript Tutorial for Beginners | https://www.youtube.com/watch?v=d56mG7DezGs |