Error Property has no initializer en TypeScript: ¿cómo solucionarlo?
¡Hola a todos! Soy nuevo en TypeScript y Angular, y me encontré con un error muy extraño. Tengo un componente en el que declaro una propiedad, pero TypeScript se queja de que no está inicializada. Aquí está mi código:
```typescript
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-user',
template: `
`
})
export class UserComponent {
@Input() user: User;
public userName: string;
private id: number;
constructor() {
// No hago nada en el constructor
}
ngOnInit() {
this.userName = this.user.name;
this.id = this.user.id;
}
}
```
Al compilar, obtengo los siguientes errores:
- `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.`
{{ user.name }}
{{ user.email }}