← Back to TypeScript Course | Chapter 1: Introduction to TypeScript | Lesson 3 of 7

TypeScript सेट अप करना

TypeScript के साथ locally काम करने के लिए, आपको Node.js जैसा एक JavaScript runtime और TypeScript compiler चाहिए। आप npm से TypeScript install कर सकते हैं और फिर TypeScript files compile करने के लिए tsc command उपयोग कर सकते हैं।

Node.js और npm जांचना

Node.js JavaScript के लिए एक runtime शामिल करता है और npm provide करता है, जो आमतौर पर TypeScript और दूसरे development tools install करने के लिए उपयोग होता है। Installed versions जांचना confirm करने में मदद करता है कि environment तैयार है।

उदाहरण: Checking Node.js and npm

typescript
// Run in a terminal (not executable here):
// node -v
// npm -v
console.log("Check installed versions with: node -v && npm -v");

TypeScript Install करना

TypeScript को npm के साथ एक project development dependency के रूप में install किया जा सकता है। इसे locally install करना compiler version को project से associated रखता है और npm scripts या npx को वह version उपयोग करने देता है।

उदाहरण: Installing TypeScript

typescript
// Run in a terminal (not executable here):
// npm install typescript --save-dev
console.log("Installed as a project dev dependency via npm");

एक TypeScript File बनाना

TypeScript source files normally .ts extension उपयोग करती हैं। आप app.ts जैसी एक file बना सकते हैं और इसके अंदर typed TypeScript code रख सकते हैं।

उदाहरण: Creating a TypeScript File

typescript
// app.ts
let projectName: string = "My First App";
console.log(projectName);

Compiler Run करना

TypeScript compiler आमतौर पर tsc command से invoke किया जाता है। एक TypeScript file दिए जाने पर, compiler code जांचता है और एक JavaScript file generate कर सकता है जो फिर एक JavaScript runtime द्वारा execute की जा सके।

उदाहरण: Running the Compiler

typescript
// Run in a terminal (not executable here):
// tsc app.ts
let result: string = "app.ts compiled to app.js";
console.log(result);

Setup Verify करना

TypeScript install करने के बाद, आप इसका version जांचकर confirm कर सकते हैं कि compiler उपलब्ध है। एक successful version output बताता है कि TypeScript compiler आपके environment से access किया जा सकता है।

उदाहरण: Verifying the Setup

typescript
// Run in a terminal (not executable here):
// tsc --version
console.log("A version number confirms tsc is accessible");
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. npm install typescript से TypeScript install करना और फिर tsc टाइप करना जब यह सिर्फ locally installed हो, npx tsc run करने के बजाय।
  2. Source file को app.js नाम देना app.ts के बजाय, इसलिए compiler इसे plain JavaScript मानता है और type annotations syntax errors का कारण बनती हैं।
  3. सीधे node app.ts run करने की कोशिश करना, जब .ts file को पहले app.js में compile किया जाना ज़रूरी है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.