I want to achieve conditional behavior of type. When I put generic in form of object kind (array, object, tuple, record), really any composite type, then I want the type behave as a typeof field of this object, but when the given type is a primary, I want to be the same type.
type B<A> = A extends object ? A[keyof A] : A;
const tuple: [1, 2];
const element:B<typeof tuple> = 2; // # ISSUE - element can be also any method of array
const num: 1;
const numElment:B<typeof num> = 1;
Above code works but for composite B type enables me to assign also all method types from an Array type. My question is - how can I specify that I am interested only about things which are not functions. So only pure fields, as in example with the tuple, element should be only number.
I was trying also with extends {} or extends {[a: string | number]: any} but it was also not working, and even above snippet would break after that.