Exemplo n.º 1
0
  foo(x: t.String): t.String {
    t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')');

    var ret = function (x) {
      return x;
    }.call(this, x);

    t.assert(t.String.is(ret), 'Invalid argument ret (expected a ' + t.getTypeName(t.String) + ')');
    return ret;
  }
Exemplo n.º 2
0
function foo({ x: { y: foo, z: { bar } }, a: { bob } }): t.String {
  var ret = function (foo, bar, bob) {
    return bar;
  }.call(this, foo, bar, bob);

  t.assert(t.String.is(ret), 'Invalid argument ret (expected a ' + t.getTypeName(t.String) + ')');
  return ret;
}
Exemplo n.º 3
0
function foo(x: a.b.c.User) {
  t.assert(a.b.c.User.is(x), 'Invalid argument x (expected a ' + t.getTypeName(a.b.c.User) + ')');

  return x;
}
Exemplo n.º 4
0
function foo(x: t.Number & t.String) {
  t.assert(t.intersection([t.Number, t.String]).is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.intersection([t.Number, t.String])) + ')');

  return x;
}
Exemplo n.º 5
0
function bar(f: t.Function) {
  t.assert(t.Function.is(f), 'Invalid argument f (expected a ' + t.getTypeName(t.Function) + ')');

  return f('a');
}
Exemplo n.º 6
0
function foo(f: (x: t.String) => t.String) {
  t.assert(t.func([t.String], t.String).is(f), 'Invalid argument f (expected a ' + t.getTypeName(t.func([t.String], t.String)) + ')');

  return f('a');
}
Exemplo n.º 7
0
  static f(x: t.String) {
    t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')');

    return x;
  }
Exemplo n.º 8
0
function foo(x: [t.String, t.Number]) {
  t.assert(t.tuple([t.String, t.Number]).is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.tuple([t.String, t.Number])) + ')');

  return x;
}
Exemplo n.º 9
0
const f = x => {
  t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')');
  return x;
};
Exemplo n.º 10
0
function bar(x: t.String[]) {
  t.assert(t.list(t.String).is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.list(t.String)) + ')');

  return x;
}
Exemplo n.º 11
0
function foo(x: Array<t.String>) {
  t.assert(t.list(t.String).is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.list(t.String)) + ')');

  return x;
}
Exemplo n.º 12
0
function foo(x: t.Number, y: t.String) {
  t.assert(t.Number.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.Number) + ')');
  t.assert(t.String.is(y), 'Invalid argument y (expected a ' + t.getTypeName(t.String) + ')');

  return x + y;
}
Exemplo n.º 13
0
function foo(x: Array<[?t.Number, t.String]>) {
  t.assert(t.list(t.tuple([t.maybe(t.Number), t.String])).is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.list(t.tuple([t.maybe(t.Number), t.String]))) + ')');

  return x;
}
Exemplo n.º 14
0
function foo(x: ?tc.String) {
  tc.assert(tc.maybe(tc.String).is(x), 'Invalid argument x (expected a ' + tc.getTypeName(tc.maybe(tc.String)) + ')');

  return x || 'Empty';
}
Exemplo n.º 15
0
function getDefaultValidationErrorMessage(actual, expected, path) {
  var expectedName = t.getTypeName(expected);
  var to = path.length ? '/' + path.join('/') + ': ' + expectedName : expectedName;
  return 'Invalid value ' + stringify(actual) + ' supplied to ' + to;
}
Exemplo n.º 16
0
 Maxlength: (max) => (type) => t.refinement(t.Number(max) && t.Type(type), (t) =>
   t.length <= max, `${t.getTypeName(type)}, Maxlength ${max}`
 ),
Exemplo n.º 17
0
  EqualKeyAndProp: (property) => (type) => t.refinement(t.Type(type), (o) => {
    for (let key in o) {
      const prop = o[key][property]

      if (key !== prop) {
        throw new TypeError(`[tcomb] ivalid value \`${prop}\`<${typeof prop}> supplied to \`${t.getTypeName(type)}/${key}/${property}\` property: expected equal to key value \`${key}\`<${typeof key}>`)
      }
    }

    return true
  }, type.displayName)
Exemplo n.º 18
0
  constructor(x: t.String) {
    t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')');

    this.x = x;
  }