Avatar ·

TypeScript में 'Property has no initializer' त्रुटि: इसे कैसे ठीक करें?

सभी को नमस्कार! मैं TypeScript और Angular में नया हूँ, और मुझे एक बहुत अजीब त्रुटि का सामना करना पड़ा। मेरे पास एक component है जिसमें मैं एक property घोषित करता हूँ, लेकिन TypeScript शिकायत करता है कि यह initialized नहीं है। यहाँ मेरा कोड है: ```typescript import { Component, Input } from '@angular/core'; @Component({ selector: 'app-user', template: `

{{ user.name }}

{{ user.email }}

` }) export class UserComponent { @Input() user: User; public userName: string; private id: number; constructor() { // कंस्ट्रक्टर में कुछ नहीं कर रहा } ngOnInit() { this.userName = this.user.name; this.id = this.user.id; } } ``` कंपाइल करने पर मुझे ये त्रुटियाँ मिलती हैं: - `Property 'user' has no initializer and is not definitely assigned in the constructor.` - `Property 'userName' has no initializer and is not definitely assigned in the constructor.` - `Property 'id' has no initializer and is not definitely assigned in the constructor.`