I am looking for a way to create a type
that can accommodate any number of properties following a predefined pattern, like so:
type Values = {
id: number;
id1?: number;
id2?: number;
id3?: number;
// ...
somethingElse: string;
anotherOne: number;
};
However, since I don't know the exact amount of ids in advance, I was wondering if there is a solution similar to this:
// pseudo-code
type Values = {
id: number;
[`id${index}`?: number];
somethingElse: string;
anotherOne: number;
};
This way, I could avoid using [k: string]: number
.
If such an approach doesn't exist, what would be the most efficient and effective way to achieve a similar outcome without having to manually add numerous idX
properties?