in src/utils/getTSType.ts [77:153]
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;
}
function getTSTypeWithRequirements(
path: NodePath,
typeParams: TypeParameters | null,
importer: Importer,
): TypeDescriptor<TSFunctionSignatureType> {
const type = getTSTypeWithResolvedTypes(path, typeParams, importer);
type.required = !path.parentPath.node.optional;
return type;
}
function handleTSTypeLiteral(
path: NodePath,
typeParams: TypeParameters | null,
importer: Importer,
): ObjectSignatureType<TSFunctionSignatureType> {
const type: ObjectSignatureType<TSFunctionSignatureType> = {
name: 'signature',
type: 'object',
raw: printValue(path),
signature: { properties: [] },
};
path.get('members').each(param => {
if (
t.TSPropertySignature.check(param.node) ||
t.TSMethodSignature.check(param.node)
) {
const propName = getPropertyName(param, importer);
if (!propName) {