My API, specifically the Elasticsearch bulk API, requires an array of operations where each operation is a pair. The first element in the pair specifies the operation (index, update, create, delete) and the second element contains the data (excluding delete).
A simplified representation of a single operation would be:
type BulkUpdate = [{ update: { _index: string, _id: string } }, { doc: object }];
type BulkIndex = [{ index: { _index: string, _id?: string } }, object];
type BulkDelete = [{ delete: { _index: string, _id: string } }];
type BulkOperation = BulkUpdate | BulkIndex | BulkDelete;
The parameter passed to the API is a flattened array of these tuples - essentially a list of operations and optionally accompanying data.
I'm trying to figure out how to model this type in Typescript. It's not a tuple due to its undetermined length, and it's not an array because the types of elements depend on their position in the array (for example, except for BulkDelete, even indices represent the "operation" while odd ones represent the "operand").