Install Node.js and TypeScript
-
Download and install Node.js from nodejs.org (LTS version).
-
Verify installation:
npm --version
node --version
- Create a project folder and initialize:
mkdir ts-learn
cd ts-learn
npm init -y
npm install -D typescript@latest
- Create
greeter.ts:
function greeter(person: string) {
return `Hello, ${person}`;
}
const user = "Jane User";
console.log(greeter(user));
- Compile:
npx tsc greeter.ts
node greeter.js
- Add
tsconfig.json:
Edit to include "strict": true.