Concept use JSON Schema to share validation logic between PHP and JS, also for generated TypeScript definitions.
Stating with handwritten schema files and using them to generate TypeScript types is the workflow I am experimenting with.
-
Install dependencies
-
Build the TypeScript types from the JSON Schema files.
npm run build
-
Run the examples
For the PHP example:
php main.php
For the JavaScript example:
node js/validator.php