Flow Runtime
A runtime type system for JavaScript with full Flow compatibility.
What?
Provides a rich API for defining, inspecting and verifying data types in JavaScript. Any value that can be represented in JS can be represented by flow-runtime
, including full support for polymorphism and parameterized types.
See the docs for more information.
Usage
; const number = t;const string = t; string; // truestring; // falsenumber; // true string; // okstring; // throwsnumber; // oknumber; // throws const numberOrString = t; numberOrString; // oknumberOrString; // oknumberOrString; // throws const fooOrBar = t; fooOrBar; // okfooOrBar; // okfooOrBar; // throws const Thing = tobject t t; Thing; // OK Thing; // OK Thing; // throws const arrayOfStrings = t; arrayOfStrings // --------------------------------------------- const UserStatus = t; const PreferenceName = t; const UserPreferences = tobject t; const User = tobject id: t name: t email: t status: UserStatus preferences: UserPreferences; const validUser = id: 123 name: 'Sally' email: 'sally@example.com' status: 'PENDING' preferences: marketingOptIn: true ; const invalidUser = id: false // invalid name: 'Bob' email: 'bob@example.com' status: 'NOPE' // invalid preferences: marketingOptIn: true nope: true // invalid ; User; // trueUser; // false User; // OKUser; // throws TypeError