Following the question on creating a choice between types Defining a choice of index type on an interface
I now have to create a sequence of elements, usually it can be written as element1 & element2
, but since i am converting an XSD schema i want it to be a 1-to-1 match, so that new TypeScript developers won't be confused with what is going on.
Currently i have this type
type Object_Type<T> = { [P in keyof T]: T[P] };
type Sequence<A, B = {}, C = {}, D = {}, E = {}, F = {}, G = {}, H = {}, I = {}, J = {}, K = {}, L = {}, M = {}, N = {}> =
Object_Type<A>
& Object_Type<B>
& Object_Type<C>
& Object_Type<D>
& Object_Type<E>
& Object_Type<F>
& Object_Type<G>
& Object_Type<H>
& Object_Type<I>
& Object_Type<J>
& Object_Type<K>
& Object_Type<L>
& Object_Type<M>
& Object_Type<N>;
And can be used like this
const sequence: Sequence<{name: string}, {age: number}> = {
name: "John",
age: 999
};
However, it is quite extreme to manually have to define every single generic parameter, and also giving them a default value, so i was wondering if it was possible to define like so
type Sequence<...T> = Object_Type<...T>;