typescript-is icon indicating copy to clipboard operation
typescript-is copied to clipboard

Make generated code smaller by putting reusable strings to constants or functions

Open zdila opened this issue 2 years ago • 1 comments

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.

zdila avatar May 07 '22 05:05 zdila

This library reduces generated code and elapsed time through closure:

https://github.com/samchon/typescript-json#runtime-validators

samchon avatar Oct 10 '22 15:10 samchon