Add polymorphic switch arbitrary test #119
-
Currently the only 2 ways of doing polymorphism with ts_serialize is to either use We may want to expand the functionality of abstract class Abs {
}
class A extends Abs {
@PolymorphicSwitch(() => new A(), (testValue: A) => testValue.hasOwnProperty("someProperty") && testValue.someProperty > 10)
someProperty: number;
} The implication would be that the test would be applied to the class resulting from serializing to the final polymorphic type, rather than running the test on the un-serialized data. This may also serve as a test to see if the data can be serialized to the final class in the first place, though we may encounter errors while serializing, and developers may need to do sanity checks on properties that would otherwise be strictly defined, as they may not be defined for this specific instance. Another possiblity is that we allow the user to run tests against the raw JSON object, instead of a serialized class, as this may prevent issues arising from the differences between the polymorphic children. abstract class Abs {
}
class A extends Abs {
// Value is pull directly from jsonObject.someProperty
@PolymorphicSwitch(() => new A(), (testValue: unknown) => typeof testValue === "number" && testValue > 10)
someProperty: number;
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@ChrisDufourMB I think you added this recently - #120 ? |
Beta Was this translation helpful? Give feedback.
-
Implemented in #120 |
Beta Was this translation helpful? Give feedback.
Implemented in #120