After exploring the question about implementing a choice of index type on an interface Defining a choice of index type on an interface
Now, I am tasked with creating a sequence of elements. Typically it would look like element1 & element2
, but because I'm converting an XSD schema, I want it to align 1-to-1 to prevent confusion for new TypeScript developers.
Currently, this is the existing type structure:
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>;
This type can be utilized as follows:
const sequence: Sequence<{name: string}, {age: number}> = {
name: "John",
age: 999
};
However, manually defining each generic parameter and assigning default values seems excessive. Is there a way to simplify it like this?
type Sequence<...T> = Object_Type<...T>;