typescript-is
typescript-is copied to clipboard
Make generated code smaller by putting reusable strings to constants or functions
When I read the generated code it often repeats strings like "validation failed at "
, ": there are no valid alternatives"
, ": expected an object"
and many more. Putting those to const variables and then using only those consts instead should help to reduce the size. Or maybe better to create error message builder functions like this:
function expectedProperty(path, property) {
return `validation failed at ${path.join(".")}: expected '${property}' in object`;
}
Minifiers will also minify function and variable names.
This library reduces generated code and elapsed time through closure:
https://github.com/samchon/typescript-json#runtime-validators