GoogleFeud / ts-runtime-checks

A typescript transformer that automatically generates validation code from your types.
https://googlefeud.github.io/ts-runtime-checks/
MIT License
312 stars 7 forks source link

Add a parse function #4

Closed mmamedel closed 2 years ago

mmamedel commented 2 years ago

Describe the solution you'd like The idea would be to actually remove any additional properties in case they are provided.

Describe alternatives you've considered This could be done by deleting the props from the variable provided. The problem with that is the side-effect created since we would be changing the function parameter. Another option is really copying each one of the props to a new variable. It would be nice if I could use it with ExactProps it would be then very similar to a lodash deepClone but with a whitelist of the props given.

mmamedel commented 2 years ago

Just thinking better about this, I think it may make more sense to be a function like the is instead of a type. So I'm changing the subject accordingly.

GoogleFeud commented 2 years ago

Good idea, I'll add it asap! I'm thinking make it possible to enable this with ExactProps, which will delete the property in place, and add another function which validates and clones the data.

Again, thank you so much for adding this library to the benchmarks repo :D, I really didn't expect it to be this fast compared to the rest of the libraries!

GoogleFeud commented 2 years ago

Coming back to this -- enabling with ExactProps wouldn't make much sense when the assertion throws or returns so I'll just make it a parameter to the check function.

GoogleFeud commented 2 years ago

Changed my mind in the end ^, changed it so it's a parameter of the ExactProps type, if it's set to true, then instead of erroring, the extra properties will be deleted.