I have an interface, with several elements:
export interface Item {
id: string;
code: string;
createdAt: string;
updatedAt: string;
level: number;
seq: number;
hasChildren: boolean;
parentObject?: Item;
children?: Item[];
}
I wanted something like the Partial<T>
which I helpfully discovered here:
Make all properties within a Typescript interface optional
However, I would like to make one of the fields mandatory. I implemented this:
export interface ItemUpdate extends Partial<Item> {
id: string;
}
and that compiled well. However, I would like to avoid declaring it for each interface. For that, I made it more generic:
export interface UpdateOf<T> extends Partial<T> {
id: string; // the ID is the only mandatory value for an update
}
However, that is no longer compiling, returning the following error:
error TS2312: An interface may only extend a class or another interface.
I am running Angular 6.1.5, which comes with Typescript 2.9 (as far as I know).