SierraSoftworks/Iridium

Property-decorator and typescript union types

Opened this issue · 2 comments

Hi,
short question: How do I map an union type like:

interface A {
  property: string | string[];
}

to the @Property-decorator validation type for model implementation?

Hi @Manusan42 - I'm afraid this is a known limitation of the current @Property validation engine and something that I intend to address before v8.x is fully released. You can take a look at #97 for another request there if you are curious, but the current solution would be implementing a custom validation plugin which handles this for you.

Ok, if I'm in higher need for this, I look into the custom validation. Till then I just use the @Property with required-flag only.

It would be sooooo cool if v8 of Iridium can handle just any interface declaration (with union or intersection types) directly given to the @Property like requested in Issue #81.

Edit: No, even better: To use the model validation just like the interface itself, it would be the most easiest way (for the user) to simply give the interface (which the model implements) into an decorator for the whole model or something similar which automates the model creation by interface process to eliminate any redundancy.

I hope you find some time in near future and thanks again for the fast reply.

Best regards