Safely Constructing Class Schema Instances in TypeScript with Effect Library
How do you safely construct class schema instances?
Goals for a constructor function:
- Signature: (obj: A) => Effect.Effect<A, ParseError> - TS error when passing nested instances of other classes without constructing them
I need this quite often when working with objects that include invariant validation embedded as schema filters. I want to be able to transform an object and re-validate it after.
I ended up creating custom constructors for everything and using declared __brands. Any tips on how to improve on this solution?
I'm specifically looking for feedback: - Any built-in solution I'm missing? - Any TS-Wizards who came up with a generic version of a "safe-constructor" function?