ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

Getting value/index types of generic mapped type

Open isaac-j-miller opened this issue 3 years ago • 0 comments

Suppose I have a type

 type GenericMappedType<T extends string | number, V> = {
    [K in T]: V;
}

If the type were

type SimpleMappedType<T>  = Record<string, T>;

I would be able to get the value type by using the method Type.getStringIndexType(). However, with the generic type, I don't see any way of doing something similar, or even finding out that V is the value type of the mapped type, and that K, which extends T is the index type.

It would be nice if there were a function like MappedTypeNode.getIndexType() and MappedTypeNode.getValueType() for this sort of type.

isaac-j-miller avatar Aug 02 '22 16:08 isaac-j-miller