Package Exports
- babel-plugin-tcomb
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-tcomb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Setup
npm install babel-plugin-tcombWebpack config
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel?plugins=babel-plugin-tcomb'
}
]
}Supported features
Built-in and user defined types (struct combinator)
import t from 'tcomb';
function foo(x: t.String) {
return x;
}
foo(1); // => throws [tcomb] Invalid value 1 supplied to Stringmaybe combinator
function foo(x: ?t.String) {
return x || 'Empty';
}list combinator
function foo(x: Array<t.String>) {
return x;
}tuple combinator
function foo(x: [t.String, t.Number]) {
return x;
}union combinator
function foo(x: t.String | t.Number) {
return x;
}dict combinator
function foo(x: {[key: t.String]: t.Number}) {
return x;
}intersection combinator
function foo(x: t.Number & t.String) {
return x;
}Arrow functions
const f = (x: t.String): t.String => x;Classes
class A {
foo(x: t.String): t.String {
return x;
}
}