This guide provides a structured approach to learning TypeScript, divided into lessons. Each lesson covers fundamental concepts, gradually building up to more advanced topics.
To run TypeScript files, you need to have Node.js installed. Download and install it from Node.js official website.
After installing Node.js, install TypeScript globally by running:
npm install -g typescriptVerify the installation:
tsc --versionTo create a new TypeScript project, run:
mkdir my-typescript-project && cd my-typescript-project
npm init -y
npm install typescript --save-devInitialize a TypeScript configuration file:
tsc --initThis creates a tsconfig.json file, allowing you to customize TypeScript settings.
Create a sample TypeScript file (index.ts):
const message: string = 'Hello, TypeScript!';
console.log(message);Compile the file to JavaScript:
tsc index.tsThis generates an index.js file. Run it using Node.js:
node index.jsYou can also use ts-node to run TypeScript files without compiling manually:
npm install -g ts-nodeRun the TypeScript file directly:
ts-node index.tsThis method is useful for quick testing and development.
We recommend using Visual Studio Code (VS Code) for TypeScript development. Download it from VS Code official website.
- ESLint – Ensures code quality
- Prettier – Formats code automatically
- TypeScript Language Support – Improves TypeScript development experience