I have the following C# class:
public class Envelope<T> {
public List<Error> Errors { get; private set; } = new List<Error>();
public Paging Paging { get; private set; }
public List<T> Result { get; private set; } = new List<T>();
public Envelope(T result) : this(new List<T> { result }, null, new List<Error>()) { }
public Envelope(List<T> result) : this (result, null, new List<Error>()) { }
public Envelope(List<Error> errors) : this(new List<T>(), null, errors) { }
public Envelope(List<T> result, Paging paging, List<Error> errors) {
Errors = errors;
Paging = paging;
Result = result;
}
}
I need to convert this class to TypeScript on an Angular 6 project so I did:
export class Envelope<T> {
errors: Error[];
paging: Paging;
result: T[];
constructor(result: T[], paging: Paging, errors: Error[]) {
this.errors = errors;
this.paging = paging;
this.result = result;
}
}
The problem is that Typescript does not allow more than one constructor so replicating the quite different constructors I have in C# seems impossible.
Is there a way to do this?
Should Envelope be an interface in TypeScript?
Basically Envelope is a Wrapper for an API response to contain various objecs such as the Result itself, Paging and List of possible errors.