Avatar ·

Fehler "Property has no initializer" in TypeScript: Wie beheben?

Hallo zusammen! Ich bin neu in TypeScript und Angular und bin auf einen sehr seltsamen Fehler gestoßen. Ich habe eine Component, in der ich eine Property deklariere, aber TypeScript beschwert sich, dass sie nicht initialisiert ist. Hier ist mein Code: ```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() { // Mache nichts im constructor } ngOnInit() { this.userName = this.user.name; this.id = this.user.id; } } ``` Bei der Kompilierung erhalte ich folgende Fehler: - `Property 'user' has no initializer and is not definitel`