import * as ts from "typescript" ; import { Context } from "./contexts/Context" ; import { getError } from "./getError" ; import getTypeCall from "./getTypeCall" ; import { GENERIC_PARAMS } from "./helpers" ; import { log } from "./log" ; export function processGetTypeCallExpression ( node , context ) { if ( context . trySetGetTypeIdentifier ( node . expression as ts . Identifier ) && context . config . debugMode ) { log . info ( "Identifier of existing getType() call stored inside context." ) ; } let genericTypeNode = node . typeArguments ?. [ 0 ] ; if ( ! genericTypeNode ) { throw getError ( node , "Type argument 'TType' of function getType<TType>() is missing." ) ; } let genericType = context . typeChecker . getTypeAtLocation ( genericTypeNode ) ; if ( genericType . flags == ts . TypeFlags . TypeParameter ) { if ( ts . isTypeReferenceNode ( genericTypeNode ) && ts . isIdentifier ( genericTypeNode . typeName ) ) { return ts . factory . createParenthesizedExpression ( ts . factory . createBinaryExpression ( ts . factory . createIdentifier ( GENERIC_PARAMS ) , ts . SyntaxKind . AmpersandAmpersandToken , ts . factory . createPropertyAccessExpression ( ts . factory . createIdentifier ( GENERIC_PARAMS ) , ts . factory . createIdentifier ( genericTypeNode . typeName . escapedText . toString ( ) ) ) ) ) ; } return undefined ; } else { const genericTypeSymbol = genericType . getSymbol ( ) ; if ( ! genericTypeSymbol ) { throw getError ( node , "Symbol of generic type argument not found." ) ; } return getTypeCall ( genericType , genericTypeSymbol , context , ts . isTypeReferenceNode ( genericTypeNode ) ? genericTypeNode . typeName : undefined ) ; } }