I have an API (the elasticsearch bulk API) that accepts an array of operations, which are basically pairs where the first element is object specifying the operation (index, update, create, delete) and the second is the data (not in the case of delete).
A single operation could be typed as (simplified):
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 entire parameter is then a flattened array of the above tuples - a list of operations and optionally data.
How do I model this type in Typescript? It's not a tuple as it has indeterminate length, and it's not an array as element types depend on their index (eg, with the exception of BulkDelete, the even indices contain the "operation" and the odds ones the "operand").