Convert Array to Interface Array

  angular, angular12, typescript

On an Angular 12 application I have the following environment:

export const environment = {
  production: false,
  applications: [
    { name: "Api", url: "https://localhost:5001" },
    { name: "Bot", url: "https://localhost:5003"}
  ],
}

And I create an Application interface and EnvironmentService class:

export interface Application {
  name: string;
  url: string;
}

export class EnvironmentService {

  constructor() {}

  get production() : boolean { return environment.production; }

  get applications() : Application[] { return environment.applications };

}

But I get an error:

Type '{ name: string; url: string; }[]' is not assignable to type 'Application[]'.

How can I convert environment.applications to Application[]?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.