ts-morph
ts-morph copied to clipboard
Getting value/index types of generic mapped type
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.