an example for such usecase would be:
type OnlyExtendArr = ???;
const arr1: OnlyExtendArr =
[
{}, //ok
{name: 'name'}, //ok
{name:"name",age: 'age'}, //ok
{age: 'age'} // should error - 'name' is required so this item's type would extend previous type
];
in this example, I want that the type of each element would extend the previous type.
more practically I want to define a type where's the item in the index n should extend the item in the index n-1 but I don't know how to write it.
is it possible using typescript?
a good start would be extracting the type of the last element in the array, which seems to be not so simple (because you can't access the -1 element in typescript) (solution for this here)
Last element in the array:
type LengthOfTuple<T extends any[]> = T extends { length: infer L } ? L : never;
type DropFirstInTuple<T extends any[]> = ((...args: T) => any) extends (arg: any, ...rest: infer U) => any ? U : T;
type LastInTuple<T extends any[]> = T[LengthOfTuple<DropFirstInTuple<T>>];
type Stuff = [number, boolean, '10'];
type last = LastInTuple<Stuff> //'10'