let obj: {
id_1: number;
id_2: number;
}[] = [];
Array should contain object or objects with both the defined keys id_1 and id_2, but cannot be empty
I am new to TS and cannot understand the above behaviour, someone please help.
you can create a specific Type to make an "unemptyable" array. Ref here
Eg : Ts playground
EDIT : eg if the playground is not working
type NonEmptyArrayTest<T> = [T, ...T[]];
let obj: NonEmptyArrayTest<{
id_1: number;
id_2: number;
}>;