In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter.
356143
function getContextualTypeForArgument(callTarget, arg) {
            var args = getEffectiveCallArguments(callTarget);
            var argIndex = ts.indexOf(args, arg);
            if (argIndex >= 0) {
                var signature = getResolvedOrAnySignature(callTarget);
                return getTypeAtPosition(signature, argIndex);
            }
            return undefined;
        }
623794
private Argument functionArgument(Data data, boolean varKeyUpperCase) throws TemplateException {
	return functionArgument(data, null, varKeyUpperCase);
    }
1103379
function mapCoerceFunction(type, strType, coerceFunction) {
    coerceFunction = coerceFunction || type.coerce;
    if (typeof strType !== 'string' || typeof coerceFunction !== 'function') {
        getLogger('map-coerce-function')
            .warn(`Bad attempt at mapping coerce function for type: ${type.name} to: ${strType}`);
        return;
    }
    coerceFunctions[strType] = coerceFunction;
    coerceFunctionMap.set(type, strType);
}
399268
public void negotiateInitialValueTypes() {
        // Either of the function result type or parameter type could be null or a specific supported value type, or a generic
        // NUMERIC. Replace any "generic" type (null or NUMERIC) with the more specific type without over-specifying
        // -- the BEST type might only become clear later when the context/caller of this function is parsed, so don't
        // risk guessing wrong here just for the sake of specificity.
        // There will be a "finalize" pass over the completed expression tree to finish specifying any remaining "generics".

        // DO use the type chosen by HSQL for the parameterized function as a specific type hint
        // for numeric constant arguments that could either go decimal or float.
        AbstractExpression typing_arg = m_args.get(m_resultTypeParameterIndex);
        VoltType param_type = typing_arg.getValueType();
        VoltType value_type = getValueType();
        // The heuristic for which type to change is that any type (parameter type or return type) specified so far,
        // including NUMERIC is better than nothing. And that anything else is better than NUMERIC.
        if (value_type != param_type) {
            if (value_type == null) {
                value_type = param_type;
            }
            else if (value_type == VoltType.NUMERIC) {
                if (param_type != null) {
                    value_type = param_type;
                }
                // Pushing a type DOWN to the argument is a lot like work, and not worth it just to
                // propagate down a known NUMERIC return type,
                // since it will just have to be re-specialized when a more specific type is inferred from
                // the context or finalized when the expression is complete.
            } else if ((param_type == null) || (param_type == VoltType.NUMERIC)) {
                // The only purpose of refining the parameter argument's type is to force a more specific
                // refinement than NUMERIC as implied by HSQL, in case that might be more specific than
                // what can be inferred later from the function call context.
                typing_arg.refineValueType(value_type, value_type.getMaxLengthInBytes());
            }
        }
        if (value_type != null) {
            setValueType(value_type);
            if (value_type != VoltType.INVALID && value_type != VoltType.NUMERIC) {
                int size = value_type.getMaxLengthInBytes();
                setValueSize(size);
            }
        }
    }
840372
def typed_range(type_func, minimum, maximum):
    
    @functools.wraps(type_func)
    def inner(string):
        result = type_func(string)
        if not result >= minimum and result <= maximum:
            raise argparse.ArgumentTypeError(
                    "Please provide a value between {0} and {1}".format(
                        minimum, maximum))
        return result
    return inner
71793
function showTypeWith(types) {
    var names = Z.chain (typeVarNames, types);
    return function(t) {
      var code = 'a'.charCodeAt (0);
      return when (t.type === FUNCTION)
                  (parenthesize (I))
                  ((show (t)).replace (/\bUnknown\b/g, function() {
                     // eslint-disable-next-line no-plusplus
                     do var name = String.fromCharCode (code++);
                     while (names.indexOf (name) >= 0);
                     return name;
                   }));
    };
  }
13295
function (expression, types) {
        var args = types.split(" | "),
            i, len, found = false;

        for (i=0, len=args.length; i < len && !found && expression.hasNext(); i++) {
            found = this.isType(expression, args[i]);
        }

        return found;
    }
765315
function compose() {
  var fnList = arguments;
  return function composed(initialArg) {
    var ret = initialArg;
    for (var i = 0; i < fnList.length; i++) {
      var fn = fnList[i];
      ret = fn.call(null, ret);
    }
    return ret;
  };
}
428557
private static <T> void mapTypeVariablesToArguments(final Class<T> cls,
            final ParameterizedType parameterizedType, final Map<TypeVariable<?>, Type> typeVarAssigns) {
        // capture the type variables from the owner type that have assignments
        final Type ownerType = parameterizedType.getOwnerType();

        if (ownerType instanceof ParameterizedType) {
            // recursion to make sure the owner's owner type gets processed
            mapTypeVariablesToArguments(cls, (ParameterizedType) ownerType, typeVarAssigns);
        }

        // parameterizedType is a generic interface/class (or it's in the owner
        // hierarchy of said interface/class) implemented/extended by the class
        // cls. Find out which type variables of cls are type arguments of
        // parameterizedType:
        final Type[] typeArgs = parameterizedType.getActualTypeArguments();

        // of the cls's type variables that are arguments of parameterizedType,
        // find out which ones can be determined from the super type's arguments
        final TypeVariable<?>[] typeVars = getRawType(parameterizedType).getTypeParameters();

        // use List view of type parameters of cls so the contains() method can be used:
        final List<TypeVariable<Class<T>>> typeVarList = Arrays.asList(cls
                .getTypeParameters());

        for (int i = 0; i < typeArgs.length; i++) {
            final TypeVariable<?> typeVar = typeVars[i];
            final Type typeArg = typeArgs[i];

            // argument of parameterizedType is a type variable of cls
            if (typeVarList.contains(typeArg)
            // type variable of parameterizedType has an assignment in
                    // the super type.
                    && typeVarAssigns.containsKey(typeVar)) {
                // map the assignment to the cls's type variable
                typeVarAssigns.put((TypeVariable<?>) typeArg, typeVarAssigns.get(typeVar));
            }
        }
    }
1357655
function(fun) {
      var fixArgs = _.rest(arguments);

      var f = function() {
        var args = fixArgs.slice();
        var arg = 0;

        for ( var i = 0; i < (args.length || arg < arguments.length); i++ ) {
          if ( args[i] === _ ) {
            args[i] = arguments[arg++];
          }
        }

        return fun.apply(null, args);
      };

      f._original = fun;

      return f;
    }
826316
private void appendFunctionParamAnnotations(
      StringBuilder sb, FunctionType funType, Node paramNode) {
    int minArity = funType.getMinArity();
    int maxArity = funType.getMaxArity();
    List<JSType> formals = ImmutableList.copyOf(funType.getParameterTypes());
    for (int i = 0; i < formals.size(); i++) {
      sb.append(" * ");
      appendAnnotation(sb, "param", getParameterJSDocType(formals, i, minArity, maxArity));
      String parameterName = getParameterJSDocName(paramNode, i);
      sb.append(" ").append(parameterName).append("\n");
      if (paramNode != null) {
        paramNode = paramNode.getNext();
      }
    }
  }
546284
private void markDCPNumberContext(Node n)
    {
        if (inDirectCallFunction && n.getType() == Token.GETVAR) {
            int varIndex = theFunction.getVarIndex(n);
            if (theFunction.isParameter(varIndex)) {
                parameterUsedInNumberContext = true;
            }
        }
    }
61849
def infer_typing_typevar_or_newtype(node, context=None):
    """"""
    try:
        func = next(node.func.infer(context=context))
    except InferenceError as exc:
        raise UseInferenceDefault from exc

    if func.qname() not in TYPING_TYPEVARS_QUALIFIED:
        raise UseInferenceDefault
    if not node.args:
        raise UseInferenceDefault

    typename = node.args[0].as_string().strip("'")
    node = extract_node(TYPING_TYPE_TEMPLATE.format(typename))
    return node.infer(context=context)
1347592
def parameter_converter(*convert_types):
    '''
    
    '''
    def inner(func):
        for ct in convert_types:
            ParameterConverter._register_converter(func, ct)
        return func
    return inner
566650
function filterTransform (args, math, scope) {
    let x, callback

    if (args[0]) {
      x = args[0].compile().evaluate(scope)
    }

    if (args[1]) {
      if (isSymbolNode(args[1]) || isFunctionAssignmentNode(args[1])) {
        // a function pointer, like filter([3, -2, 5], myTestFunction)
        callback = args[1].compile().evaluate(scope)
      } else {
        // an expression like filter([3, -2, 5], x > 0)
        callback = compileInlineExpression(args[1], math, scope)
      }
    }

    return filter(x, callback)
  }
270304
private Pair<Type, Identifier> parseMixedType(EnclosingScope scope) {
		Token lookahead;
		int start = index;

		if ((lookahead = tryAndMatch(true, Function, Method)) != null) {
			// At this point, we *might* have a mixed function / method type
			// definition. To disambiguate, we need to see whether an identifier
			// follows or not.
			// Similar to normal method declarations, the lifetime parameters
			// go before the method name. We do not allow to have captured
			// lifetimes for mixed method types.
			Tuple<Identifier> lifetimes = new Tuple<>();
			if (lookahead.kind == Method && tryAndMatch(true, LeftAngle) != null) {
				// mixed method type with lifetime parameters
				scope = scope.newEnclosingScope();
				lifetimes = parseLifetimeParameters(scope);
			}
			// Now try to parse the identifier
			Identifier id = parseOptionalIdentifier(scope);

			if (id != null) {
				// Yes, we have found a mixed function / method type definition.
				// Therefore, we continue to pass the remaining type parameters.
				Tuple<Type> paramTypes = parseParameterTypes(scope);
				Tuple<Type> returnTypes = new Tuple<>();

				if (lookahead.kind == Function) {
					// Functions require a return type (since otherwise they are
					// just nops)
					match(MinusGreater);
					// Third, parse the return type
					returnTypes = parseOptionalParameterTypes(scope);
				} else if (tryAndMatch(true, MinusGreater) != null) {
					// Third, parse the (optional) return type. Observe that
					// this is forced to be a
					// unit type. This means that any tuple return types must be
					// in braces. The reason for this is that a trailing comma
					// may be part of an enclosing record type and we must
					// disambiguate
					// this.
					returnTypes = parseOptionalParameterTypes(scope);
				}

				// Done
				Type type;
				if (lookahead.kind == Token.Kind.Function) {
					type = new Type.Function(paramTypes, returnTypes);
				} else {
					type = new Type.Method(paramTypes, returnTypes, new Tuple<>(),
							lifetimes);
				}
				return new Pair<>(annotateSourceLocation(type,start), id);
			} else {
				// In this case, we failed to match a mixed type. Therefore, we
				// backtrack and parse as two separate items (i.e. type
				// identifier).
				index = start; // backtrack
			}
		}

		// This is the normal case, where we expect an identifier to follow the
		// type.
		Type type = parseType(scope);
		Identifier id = parseIdentifier();
		return new Pair<>(type, id);
	}
965271
function TypeCheckExtended(parameter, type, required = true, format = null) {
  /*
  Used at top of functions to validate type of parameters received.
    parameter  <-----  Any (The parameter that's being checked)
    type       <-----  String (See types)
    required   <-----  String (If not required, value must be falsey to pass check)
    format     <-----  Array (used by enum)

  To allow intuitive type checking, TypeCheck alters default JS 'typeof' as follows:
    'array': now independent type separate from object
    'object': now excludes objects that are also arrays
    'enum': ensures parameter is in specfied array. Pass allowed values as 'format'
  */
  const types = [
    'array',
    'boolean',
    'enum',
    'function',
    'number',
    'object',
    'string',
    'symbol',
    'undefined',
  ];

  const extendedTypes = ['array', 'enum'];

  if (!types.includes(type)) {
    throw new Error(`TypeCheck Error: (${type}) is not a valid type.`);
  }

  if (required || (!required && parameter)) {
    // Differentiate between arrays and non-array objects
    if (
      (type === 'array' && !Array.isArray(parameter)) ||
      (type === 'object' && Array.isArray(parameter))
    ) {
      throw new Error(`TypeCheck Error: (${parameter}) should be ${type}`);
    }

    // Enum Checks
    if (type === 'enum') {
      if (format.includes(parameter)) {
        return true;
      }
      throw new Error(`TypeCheck Error: (${parameter}) is invalid enum.`);
    }

    if (!extendedTypes.includes(type) && typeof parameter !== type) {
      throw new Error(`TypeCheck Error: (${parameter}) should be ${type}`);
    }
  }

  return true;
}