io-types for Angular 2 Components
Run Time Type Checking for Inputs/Outputs
Please note that io-types is currently proof-of-concept.
Like React's propTypes, io-types let you describe expected input and output for your Angular 2 components. Assertions are run in development mode letting you easily catch bad bindings.
To use, install the dependency using npm:
npm install io-types
Then write assertions for your component's inputs:
Now passing non-boolean values to
active results in an error. For example:
Invalid value for 'MyComponent.active': ↳ Expected '123' to be of type 'boolean'
Similarly, you can use the same assertions to check function arguments. This helps you make assertions about event handler callbacks:
Right now io-types is basically a proof-of-concept. Future iterations may include an API similar to React's propTypes in addition to using Reflection for simple assertions.