docs: function castType(val, type, def) {
      function cast() {
          if (!is_1.isValue(val))
              return to_1.toDefault(null, def);
          // If no type specified try to get automatically.
          type = type || getType(val);
          if (is_1.isArray(type)) {
              return to_1.toArray(val)
                  .map(function (v, i) { return castType(v, type[i] || type[i - 1] || type[0]); });
          }
          else if (is_1.isFunction(type)) {
              val = to_1.toArray(val);
              return type.apply(void 0, val);
          }
          else if (is_1.isString(type)) {
              type = type.toLowerCase();
              var func = toMap[type];
              if (func)
                  return func(val);
              return to_1.toDefault(null, def);
          }
          else {
              return val;
          }
      }
      return function_1.tryWrap(cast)(def);
  }