Generator of validation script of type defined in Flow or TypeScript.
This tool replace JSON schema or io-ts in user friendly way when you use static typed JavaScript. You can use just your type definition in Flow or Typescript and generate validation functions.
Ideal for API validation using JSON or CSV.
NOTE: This tool use babel-plugin-tcomb. It contains older
definition of Flow types. This tool is for basic
types checking. Not use unnecessarily complex type definition.
- CLI API to generate Flow typed validation functions
- CLI API to generate TypeScript typed validation functions
- WebPack plugin
npm install --save-dev runtime-type-validation-generator
npm install --save tcomb
rtvg ./typesDefinitionFile.js ./validationsFile.js
or
npx rtvg ./typesDefinitionFile.js ./validationsFile.js
import type { Data } from "./typesDefinitionFile.js";
import { validateData } from "./validationsFile.js";
async function getData(url: string): Data {
const response = await fetch(url);
return validateData(await response.json());
}
export type Data = {
id: string,
order: number,
content: Array<Data>,
};
export function validateData(data: mixed): Data;