DefinitelyTyped/types/check-types/check-types-tests.ts
idchlife d19ddb855d Types for check-types (#22554)
* Types for check-types

* added version

* added tsconfig.json

* fixes for tslint

* tests, some improv

* missing semicolon fix

* added tests file to tsconfig

* fixed errors

* removed redundant comment

* updated tests and types with info from creator of lib
2018-01-02 11:27:59 -08:00

58 lines
972 B
TypeScript

import * as check from "check-types";
const a: boolean = check.number(2);
const b: any = 2;
if (check.string(b)) {
const c = b.slice(0, 1);
}
check.map({ val: 1, val2: 2 }, { val: check.number, val2: check.string });
check.even(3);
check.not.even(3);
check.maybe.even(2);
check.assert.like({ foo: 'bar' }, { baz: 'qux' });
check.assert(false, "msg", Error);
check.assert.not.like({ foo: 'bar' }, { baz: 'qux' });
check.assert.maybe.like(undefined, { foo: 'bar' });
check.assert(function a(): any { return {}; }, 'Something went wrong', Error);
check.apply([ 'foo', 'bar', '' ], check.nonEmptyString);
check.any(
check.apply(
[ 1, 2, 3, '' ],
check.string
)
);
check.any(
check.map(
{ foo: 0, bar: '' },
{ foo: check.number, bar: check.string }
)
);
check.all(
check.map(
{ foo: 0, bar: '' },
{ foo: check.number, bar: check.string }
)
);
check.all(
check.apply(
[ 1, 2, 3, '' ],
check.string
)
);