Lesson 30 of 55 · javascript
Intro to TypeScript (Optional)
Duration: 12 mins
TypeScript adds static typing on top of JavaScript.
npm install -D typescript
npx tsc --init
tsconfig.json
{
"target": "es2020",
"module": "esnext",
"strict": true,
"sourceMap": true
}
Simple TS file:
function greet(name: string): string {
return `Hi, ${name}`;
}
console.log(greet('World'));
Compile with npx tsc.
Benefits
- Early detection of type errors.
- Rich IDE autocomplete.
- Gradual adoption – rename
.jsto.tsone file at a time.