Closed jpbaking closed 2 years ago
Hmm, weird. We have tests for validating inherited properties, so it should be supported. We'll need to investigate.
https://github.com/joiful-ts/joiful/blob/master/test/unit/inheritance.test.ts
I can't reproduce this issue. I added the test case to inheritance.test.ts
, and it passes.
Is it possible that you have not imported reflect-metadata
in your application's entry point, or you have imported it in multiple files? (Importing it mulitple times might create multiple metadata maps/caches)
it('works for issue #222', () => {
class Foo {
@jf.string().required().min(3).regex(/[a-zA-Z][a-zA-Z0-9-_]+[a-zA-Z0-9]/)
foo!: string;
}
class Bar extends Foo {
@jf.string().required().min(3).regex(/[a-zA-Z][a-zA-Z0-9-_]+[a-zA-Z0-9]/)
bar!: string;
}
const bar: Bar = new Bar();
// bar.foo // undefined
bar.bar = 'sample-val1d_value';
const { error } = validator.validate(bar);
expect(error?.details?.length).toStrictEqual(1); // should be because of bar.foo
});
Closing. If you still have this problem, please provide a minimal reproducible example.
Given:
When:
Expect:
Actual: