function handleTSIndexedAccessType()

in src/utils/getTSType.ts [375:408]


function handleTSIndexedAccessType(
  path: NodePath,
  typeParams: TypeParameters | null,
  importer: Importer,
): SimpleType {
  const objectType = getTSTypeWithResolvedTypes(
    path.get('objectType'),
    typeParams,
    importer,
  ) as ObjectSignatureType<TSFunctionSignatureType>;
  const indexType = getTSTypeWithResolvedTypes(
    path.get('indexType'),
    typeParams,
    importer,
  ) as LiteralType;

  // We only get the signature if the objectType is a type (vs interface)
  if (!objectType.signature)
    return {
      name: `${objectType.name}[${indexType.value.toString()}]`,
      raw: printValue(path),
    };
  const resolvedType = objectType.signature.properties.find(p => {
    // indexType.value = "'foo'"
    return p.key === indexType.value.replace(/['"]+/g, '');
  });
  if (!resolvedType) {
    return { name: 'unknown' };
  }
  return {
    name: resolvedType.value.name,
    raw: printValue(path),
  };
}