babel-plugin-tcomb

raw JSON →
0.4.0 verified Sat Apr 25 auth: no javascript abandoned

Babel plugin that adds runtime type checking from Flow annotations using tcomb. Version 0.4.0, released 2020-09-05. This is the latest stable release; prior versions support Babel 6, latest supports Babel 7. Transforms Flow type annotations into runtime assertions via tcomb. Different from flow-remove-types or babel-plugin-transform-flow-strip-types because it keeps the type information for runtime validation. Works alongside Flow for hybrid static + dynamic checking. Supports refinement types, immutability enforcement, and IO boundary validation. Abandoned as of November 2021; no commits or releases since 0.4.0.

error Error: Cannot find module 'tcomb'
cause tcomb is a peer dependency and not installed automatically.
fix
npm install --save-dev tcomb
error TypeError: [tcomb] Invalid value "x" supplied to b: Number
cause Runtime type check failed – argument type mismatch.
fix
Correct the call to pass a number: sum(1, 2);
error Error: Plugin 0 specified in "..." provided an invalid property of type "..."
cause Plugin order or misconfiguration in .babelrc.
fix
Ensure plugins array contains 'tcomb' after 'syntax-flow' and before 'transform-flow-strip-types'. Try passPerPreset: true.
error ReferenceError: t is not defined
cause tcomb not imported or requireable in your source module.
fix
Add import t from 'tcomb' at the top of your file, or ensure CommonJS require('tcomb') works.
breaking Version 0.4.0 requires Babel 7; incompatible with Babel 6 projects.
fix Upgrade to Babel 7 or pin to 0.3.27 for Babel 6.
deprecated Package is no longer maintained; last release 0.4.0 (2020). No bug fixes or updates for newer Babel versions.
fix Consider alternatives like babel-plugin-runtime-typecheck or TypeScript with ttypescript.
gotcha tcomb must be requireable at runtime; if using ES modules, ensure transform-modules-commonjs or similar is applied before tcomb plugin.
fix Add plugin order: transform-modules-commonjs before tcomb, or use Babel env with modules: 'commonjs'.
gotcha Passing passPerPreset: true may be required when using multiple presets to avoid conflicts.
fix Set passPerPreset: true in .babelrc.
breaking Removed support for Babel 6 in v0.4.0; no migration path for Babel 6 projects.
fix Stick with v0.3.27 for Babel 6, or upgrade entire project to Babel 7.
npm install babel-plugin-tcomb
yarn add babel-plugin-tcomb
pnpm add babel-plugin-tcomb

Shows Babel setup and runtime type checking triggered by a Flow-annotated function call with a type mismatch.

// .babelrc
{
  "plugins": [
    "syntax-flow",
    "tcomb",
    "transform-flow-strip-types"
  ]
}

// src/index.js
function sum(a: number, b: number): number {
  return a + b;
}

// This will throw at runtime:
sum(1, 'x'); // Uncaught TypeError: [tcomb] Invalid value "x" supplied to b: Number