tcomb-decorators

1.0.1 • Public • Published

tcomb-decorators

ES7 Decorators for tcomb.

Installation

npm install tcomb-decorators --save

Usage

@func

import { func } from 'tcomb-decorators';
import { String as Str } from 'tcomb';
 
class SomeClass {
    @func([Str], Str)
    someFunc(value) {
        return value + 'World';
    }
}
 
const instance = new SomeClass();
 
instance.someFunc('Hello '); // Works
instance.someFunc(null); // Throws error

@struct

Experimental: The current behaviour maybe changed in the future.

import { struct } from 'tcomb-decorators';
import { String as Str } from 'tcomb';
 
@struct({
    name: Str
})
class Person {
    constructor(name) {
        this.name = name;
    }
}
 
new Person('John Doe') // Works
new Person(); // Throws error

The struct decorator works by wrapping the constructor and using tcomb-validations validate function after class construction. So typ checking is only applyed on initialtion. Further modifications of the object does not lead to an validation again.

LISENCE

MIT

Package Sidebar

Install

npm i tcomb-decorators

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mlegenhausen