Can I implement a parent interface in Angular 4?
export interface Devices extends Array<Device> {
}
The error 'Class 'DevicesModel' incorrectly implements interface 'Devices'. Property 'includes' is missing in type DevicesModel' occurs when trying to do so.
export class DevicesModel implements Devices {
constructor() {
}
}
I suspect that since it's an instance of an array, adding other attributes to the model is not allowed.
I am separating Swagger models from application models by implementing all Swagger generated models. This way, modifications can be made without losing them when regenerated. If this isn't possible, I may need to use composition technique.
EDITs:
More Information:
This is how my Swagger YAML looks like defining rest services.
Devices:
type: array
description: list of devices
items:
$ref: '#/definitions/Device'
Service:
type: object
required:
- serviceId
- serviceName
properties:
serviceId:
type: string
deviceName:
type: string
serviceName:
type: string
port:
type: string
tag:
type: string
My Swagger generated Rest server model looks like this:
@ApiModel(description = "list of devices")
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2018-02-23T10:57:40.757-05:00")
public class Devices extends ArrayList<Device> implements Serializable {
private static final long serialVersionUID = 1L;
....
}
When generating a Typescript REST client using Swagger codegen, Devices model is created as:
export interface Devices extends Array<Device> {
}
Changing the YAML so that generated objects don't extend Array but use composition might be the safest bet:
public class Devices implements Serializable
{
private static final long serialVersionUID = 1L;
private List<Device> devices;
....
}
In Typescript:
export interface Devices {
devices: Array<Device>;
}
Since I'm new to Typescript and Angular, applying Java techniques into Typescript is adding complexity. As I continue learning, sticking to a simple solution for now seems best.
Thank you!