tycheck
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

TyCheck

TyCheck is a library used to make types both JavaScript and TypeScript and check them at runtime.

Install

On your project, using npm (or any other node package manager).

npm i tycheck

Usage

Simple usage

import { typeChecker, typeString } from 'tycheck';

const checker = typeChecker(typeString);

const validString = checker('Valid string'); // validString will have "Valid string" value
const invalidString = checker(42); // The checker will throw a type error

More complex usage

import { beArray, typeBoolean, typeChecker, typeNumber, beInterface, typeString } from 'tycheck';

const checker = typeChecker(
  beInterface({
    string: typeString,
    boolean: typeBoolean,
    array: beArray(typeNumber)
  })
);

type CheckedType = ReturnType<typeof checker>;

const checkedValue = checker({
  string: 'string value',
  boolean: true,
  array: [33, 42],
}); // Will pass and be type of CheckedType (by inference)

Contribute

Just create a Pull Request with your contribution.

The Pull Request is used to add/remove code but also as a discussion place to know if the contribution is relevant.

Install

npm i

Tests

npm test

Build

npm run build

Readme

Keywords

none

Package Sidebar

Install

npm i tycheck

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

15.7 kB

Total Files

10

Last publish

Collaborators

  • anrey