在 Angular 12 应用程序上,我有以下环境:
export const environment = {
production: false,
applications: [
{ name: "Api", url: "https://localhost:5001" },
{ name: "Bot", url: "https://localhost:5003"}
],
}
我创建了一个Application
接口和EnvironmentService
类:
export interface Application {
name: string;
url: string;
}
export class EnvironmentService {
constructor() {}
get production() : boolean { return environment.production; }
get applications() : Application[] { return environment.applications };
}
但我收到一个错误:
Type '{ name: string; url: string; }[]' is not assignable to type 'Application[]'.
我怎样才能转换environment.applications
为Application[]
?