1
votes

TypeScript shows me below erros in app.component.ts:

Argument of type '(events: Event[]) => void' is not assignable to parameter of type '(value: Event[]) => void'.

Types of parameters 'events' and 'value' are incompatible.

Type 'Event[]' is not assignable to type 'import("/home/src/app/models/event.interface").Event[]'.

Type 'Event' is missing the following properties from type 'Event': _id, name, date

Here is my code:

event.interface.ts

export interface Event{
    _id: string;
    name: string;
    date: Date;
}

app.service.ts

  getEvents(): Observable<Event[]> {
    return this.http.get<Event[]>('www.example.com/your-events')
  }

app.component.ts

  ngOnInit() {
    this.appService.getEvents().subscribe(
      (events: Event[]) => {
        this.promotersEvents = events;
      }
    )
  }

What is wrong with my code? Thanks for advice!

1
Just a wild guess that your interface overlapping with the Angular's type event, I would try to change the name of your interfaceSerg.ID

1 Answers

4
votes

You probably forgot to import the Event interface in app.service.ts or in app.component.ts and one of the Event you are referring to is the native Javascript Event.

If that doesn't help, try to rename the interface so it doesn't conflict with Ecmascript definition files.