import * as ts from "typescript" ; import { GET_TYPE_FNC_NAME , TYPE_ID_PROPERTY_NAME } from "tst-reflect" ; import { Context } from "./contexts/Context" ; import { getError } from "./getError" ; import { log } from "./log" ; param node param context returns export function isGetTypeCall ( node , context ) { if ( ts . isCallExpression ( node ) ) { if ( ( node . expression as any ) . escapedText != GET_TYPE_FNC_NAME ) { return false ; } if ( context . trySetGetTypeIdentifier ( node . expression as ts . Identifier ) && context . config . debugMode ) { log . info ( "Identifier of existing getType() call stored inside context." ) ; } const fncType = context . typeChecker . getTypeAtLocation ( node . expression ) ; if ( ! fncType . getProperty ( TYPE_ID_PROPERTY_NAME ) ) { return false ; } let genericTypeNode = node . typeArguments ?. [ 0 ] ; if ( ! genericTypeNode ) { throw getError ( node , "Type argument of function getType<T>() is missing." ) ; } return genericTypeNode ; } return false ; }