Avatar ·

TypeScript में प्रयोगात्मक डेकोरेटर्स के बारे में चेतावनी

सभी को नमस्ते! मैं TypeScript में नया हूँ और अपने class में लॉगिंग जोड़ने के लिए डेकोरेटर्स का उपयोग करने की कोशिश कर रहा हूँ। मेरे पास Visual Studio Code स्थापित है, और मैंने tsconfig.json फ़ाइल के साथ एक सरल प्रोजेक्ट बनाया है। यहाँ मेरा कोड है: ```typescript function log(target: any, propertyKey: string, descriptor: PropertyDescriptor) { const originalMethod = descriptor.value; descriptor.value = function(...args: any[]) { console.log(`मेथड ${propertyKey} को आर्गुमेंट्स के साथ कॉल किया गया:`, args); return originalMethod.apply(this, args); }; return descriptor; } class Calculator { @log add(a: number, b: number): number { return a + b; } } const calc = new Calculator(); calc.add(2, 3); ``` कम्पाइल करने पर मुझे चेतावनी मिलती है: "Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning." मैंने अपने tsconfig.json में `"experimentalDecorators": true` जोड़ने की कोशिश की,

अभी तक कोई उत्तर नहीं।

लॉग इन करें उत्तर देने के लिए

ब्लॉग