rtts_assert
raw JSON → 2.0.0-alpha.37 verified Fri May 01 auth: no javascript maintenance
A run-time type assertion library for JavaScript, used internally by Angular for runtime type checks. Current stable version is 2.0.0-alpha.37 (pre-release, adapted from v0.1.0 originally designed for Traceur). No regular release cadence—packaged within Angular monorepo. Key differentiator: provides runtime type checking akin to TypeScript's emitDecoratorMetadata, useful in testing and dynamic type validation. Lightweight with no runtime dependencies.
Common errors
error TypeError: assert.argumentTypes is not a function ↓
cause assert.argumentTypes was removed in v2.0.0.
fix
Replace with assert.type(arg1, Type), assert.type(arg2, Type), etc.
error Error: Expected argument to be a string but got 'undefined' ↓
cause assert.define first argument must be a string name, not a type reference.
fix
assert.define('MyType', ..., not assert.define(MyType, ...).
error AssertionError: Expected String, got Number. ↓
cause Value does not match the asserted type.
fix
Check the value and type: assert.type(value, ActualType).
Warnings
breaking assert.argumentTypes is deprecated and removed in v2; use assert.type instead. ↓
fix Replace assert.argumentTypes(arg1, Type, arg2, Type) with individual assert.type calls.
deprecated ES5 build script es5build.js is no longer maintained. ↓
fix Use a modern bundler (e.g., esbuild, Webpack) to transpile ES6 sources.
gotcha assert(value).is(...) returns an assertion object, not a boolean; must be called as a statement. ↓
fix Do not assign the result: use assert(value).is(Type) without assignment.
gotcha Custom types defined with assert.define must use a string name; using a class name will silently fail. ↓
fix assert.define('MyClass', fn) instead of assert.define(MyClass, fn).
breaking Predefined types like assert.string now require assert.type(value, assert.string) instead of assert(value).is(assert.string) pattern changed. ↓
fix Use assert.type(value, assert.string) or assert(value).is(assert.string) still works.
Install
npm install rtts_assert yarn add rtts_assert pnpm add rtts_assert Imports
- assert wrong
const assert = require('rtts_assert');correctimport { assert } from 'rtts_assert'; - assert.type wrong
assert(value, Type);correctassert.type(value, Type); - assert.define wrong
assert.define(MyType, function(value) { ... });correctassert.define('MyType', function(value) { ... });
Quickstart
import { assert } from 'rtts_assert';
assert.type('hello', String); // passes
assert.type(42, String); // throws: Expected String, got Number.
const value = 'test';
assert(value).is(String); // passes
assert(value).is(Number); // throws
assert.define('Email', function(value) {
assert(value).is(String);
if (value.indexOf('@') === -1) {
assert.fail('must contain @');
}
});
assert.type('user@example.com', Email); // passes
assert.type('invalid', Email); // throws: must contain @