TypeScript का Playground
In this page:
Playground में TypeScript लिखना
Playground TypeScript code enter करने और zero setup के साथ instantly compiler का output देखने के लिए एक browser-based editor provide करता है। यह beginners के लिए खासतौर पर useful है क्योंकि experiments तुरंत try किए जा सकते हैं, एक local project बनाए या कुछ install किए बिना।
उदाहरण: Writing TypeScript in the Playground
// Paste into the online Playground - no setup required
let city: string = "Mumbai";
console.log(city);
JavaScript Output देखना
Playground की सबसे useful features में से एक एक side-by-side panel है जो exactly दिखाता है कि आपका TypeScript source plain JavaScript में कैसे transform होता है। यह concrete बनाता है कि type annotations एक development-time-only feature हैं, क्योंकि वे strip हो जाती हैं और emitted JavaScript में कभी नहीं दिखती।
उदाहरण: Viewing JavaScript Output
let count: number = 5;
console.log(count);
// Playground's right panel shows this compiled to: let count = 5; console.log(count);
Type Errors Test करना
Playground आपके type करते ही TypeScript compiler की diagnostics live दिखाता है, इसे intentionally incorrect types लिखकर type system के साथ experiment करने के लिए एक great जगह बनाते हुए।
Exactly देखना कि compiler कैसे और क्यों object करता है real intuition बनाता है कि type checker आपके code के बारे में कैसे reason करता है।
उदाहरण: Testing Type Errors
let age: number = 25;
// age = "twenty"; // Playground highlights this as a type error live
console.log(age);
Compiler Options के साथ Experiment करना
Playground target और strict जैसी compiler settings के साथ experiment करने के लिए controls expose करता है बिना कभी एक tsconfig.json file छुए। इन options को toggle करना और diagnostics और generated JavaScript दोनों को बदलते देखना आपको समझने में मदद करता है कि हर setting असल में क्या control करती है।
उदाहरण: Experimenting with Compiler Options
// Playground sidebar toggle: target = ES5, strict = true
let value: number = 10;
console.log(value);
Experiments से सीखना
क्योंकि आप code का एक छोटा टुकड़ा बदल सकते हैं और immediately compiler diagnostics और generated JavaScript दोनों को update होते देख सकते हैं, Playground सीखने के लिए एक unusually fast feedback loop है।
यह एक real project में commit करने से पहले unfamiliar TypeScript syntax test करने के लिए एक convenient जगह है।
उदाहरण: Learning Through Experiments
let x: number = 2;
let y: number = 3;
console.log(x + y);
// Change a type above and watch diagnostics/output update instantly
- Playground से ऐसा code run करने की उम्मीद करना जिसे files, npm packages या filesystem चाहिए, जब यह एक छोटा in-browser sandbox है।
- Compiler-options panel ignore करना और यह सोचना कि एक type error क्यों दिखता है (या गायब हो जाता है) जब
stricttoggle किया जाए। - यह सोचना कि right-hand JavaScript output में अब भी आपकी type annotations हैं, जब वे remove कर दी गई हैं।
- TypeScript JavaScript का एक typed superset है जिसे आप
tsccompiler से plain JavaScript में compile करते हैं। - Setting up में TypeScript install करना, एक पहला
.tsprogram लिखना, और type errors early देखने के लिए इसे compile करना शामिल है। - एक
tsconfig.jsonfile compiler behavior control करती है, और TypeScript Playground आपको browser में experiment करने देता है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: