My dilemma lies in a generic interface with a field depending on the passed type.
I'm exploring the possibility of having another field that can accept any type from the passed type.
For instance:
interface sampleObject {
name: fullName
age: number
address: string
}
interface fullName{
first: string
middle: string
last: string
}
// Consider I pass in a type like sampleObject
interface genericType<T, Key = keyof T> {
field: Key // valid values are "name", "age", "address"
fieldTypes: ??? // I aim for the valid types to be fullName, number, string
}
I attempted using fieldTypes: T[keyof T]
but it returns
fullName | number | string | undefined
, triggering a ts(2322) error.
I'm uncertain if my approach is correct or not.