Triple-Slash Directives की जानकारी
In this page:
/// <reference path="./file.d.ts" />
/// <reference types="package-name" />
Reference Path Directive
Reference path directive TypeScript को बताता है कि current file check करते समय एक और declaration file include करे, जो modern module resolution से पहले dependencies को साथ wire करने का एक early तरीका था।
उदाहरण: Reference Path Directive
/// <reference path="./other-file.d.ts" />
console.log("References another declaration file for type checking");
Reference Types Directive
Reference types directive TypeScript को बताता है कि current file की compilation में एक type package (node_modules/@types से) की declarations include करे, बिना किसी explicit import की ज़रूरत के।
उदाहरण: Reference Types Directive
/// <reference types="node" />
console.log("Includes @types/node declarations without an explicit import");
Reference Lib Directive
Reference lib directive explicitly current file की checking में एक built-in TypeScript library declaration include करता है — जैसे एक specific ECMAScript version का APIs — project की tsconfig lib setting पहले से जो include करती है उससे आगे।
उदाहरण: Reference Lib Directive
/// <reference lib="es2020.promise" />
console.log("Includes a specific built-in library beyond tsconfig's lib setting");
No-Default-Lib Directive
No-default-lib directive एक declaration file को mark करता है कि यह automatically default library include नहीं करे, जो एक custom global environment authoring करते समय उपयोग होता है जिसे standard built-ins inherit नहीं करना चाहिए।
उदाहरण: No-Default-Lib Directive
/// <reference no-default-lib="true"/>
console.log("Marks this file as not including the default TypeScript library");
Triple-Slash Directives कब उपयोगी हैं
Modern TypeScript projects आमतौर पर dependency management के लिए triple-slash directives के बजाय imports और tsconfig.json पर rely करते हैं, तो आपको ये ज़्यादातर older code में या hand-written .d.ts files में मिलेंगे।
उदाहरण: When Triple-Slash Directives Are Useful
// Modern projects prefer imports + tsconfig.json:
// import { something } from "./module";
// Triple-slash directives mainly appear in older code or hand-written .d.ts files.
console.log("Triple-slash directives are largely legacy today");
/// <reference ... />को दूसरे code या comments-with-code के बाद रखना, जब यह सिर्फ file के top पर valid है।- एक modern project में
tsconfig.jsonकेincludeया एकimportके बजाय reference path directive उपयोग करना। - एक types package reference करना जो installed नहीं है, जैसे
@types/nodeके बिनाtypes="node", जो एक error है।
- ES modules code को files में organize करने के लिए
importऔरexportउपयोग करते हैं, default exports सहित। - Namespaces related code group करते हैं, और declaration merging एक ही नाम वाली कई declarations combine करता है।
- Ambient declarations और triple-slash directives आपके source के बाहर exist करने वाले code और dependencies describe करते हैं।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: