function handleTSTypeReference()

in src/utils/getTSType.ts [65:123]


function handleTSTypeReference(
  path: NodePath,
  typeParams: TypeParameters,
  importer: Importer,
): TypeDescriptor<TSFunctionSignatureType> | null {
  let type: TypeDescriptor<TSFunctionSignatureType>;
  if (t.TSQualifiedName.check(path.node.typeName)) {
    const typeName = path.get('typeName');

    if (typeName.node.left.name === 'React') {
      type = {
        name: `${typeName.node.left.name}${typeName.node.right.name}`,
        raw: printValue(typeName),
      };
    } else {
      type = { name: printValue(typeName).replace(/<.*>$/, '') };
    }
  } else {
    type = { name: path.node.typeName.name };
  }

  const resolvedPath =
    (typeParams && typeParams[type.name]) ||
    resolveToValue(path.get('typeName'), importer);

  if (path.node.typeParameters && resolvedPath.node.typeParameters) {
    typeParams = getTypeParameters(
      resolvedPath.get('typeParameters'),
      path.get('typeParameters'),
      typeParams,
      importer,
    );
  }

  if (typeParams && typeParams[type.name]) {
    // Open question: Why is this `null` instead of `typeParams`
    type = getTSTypeWithResolvedTypes(resolvedPath, null, importer);
  }

  if (resolvedPath && resolvedPath.node.typeAnnotation) {
    type = getTSTypeWithResolvedTypes(
      resolvedPath.get('typeAnnotation'),
      typeParams,
      importer,
    );
  } else if (path.node.typeParameters) {
    const params = path.get('typeParameters').get('params');

    type = {
      ...(type as SimpleType),
      elements: params.map((param: NodePath) =>
        getTSTypeWithResolvedTypes(param, typeParams, importer),
      ),
      raw: printValue(path),
    };
  }

  return type;
}