TypeScript सेट अप करना
In this page:
Node.js और npm जांचना
Node.js JavaScript के लिए एक runtime शामिल करता है और npm provide करता है, जो आमतौर पर TypeScript और दूसरे development tools install करने के लिए उपयोग होता है। Installed versions जांचना confirm करने में मदद करता है कि environment तैयार है।
उदाहरण: Checking Node.js and npm
// 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
// 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
// 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
// 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
// Run in a terminal (not executable here):
// tsc --version
console.log("A version number confirms tsc is accessible");
npm install typescriptसे TypeScript install करना और फिरtscटाइप करना जब यह सिर्फ locally installed हो,npx tscrun करने के बजाय।- Source file को
app.jsनाम देनाapp.tsके बजाय, इसलिए compiler इसे plain JavaScript मानता है और type annotations syntax errors का कारण बनती हैं। - सीधे
node app.tsrun करने की कोशिश करना, जब.tsfile को पहलेapp.jsमें compile किया जाना ज़रूरी है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: