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; }
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; }
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; }
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; }
function bar(f: t.Function) { t.assert(t.Function.is(f), 'Invalid argument f (expected a ' + t.getTypeName(t.Function) + ')'); return f('a'); }
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'); }
static f(x: t.String) { t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')'); return x; }
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; }
const f = x => { t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')'); return x; };
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; }
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; }
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; }
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; }
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'; }
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; }
Maxlength: (max) => (type) => t.refinement(t.Number(max) && t.Type(type), (t) => t.length <= max, `${t.getTypeName(type)}, Maxlength ${max}` ),
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)
constructor(x: t.String) { t.assert(t.String.is(x), 'Invalid argument x (expected a ' + t.getTypeName(t.String) + ')'); this.x = x; }