Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeCheck.Check and TypeCheck.Errors inconsistent with getter methods #1193

Open
hstaudacher opened this issue Mar 3, 2025 · 0 comments
Open
Labels

Comments

@hstaudacher
Copy link

hstaudacher commented Mar 3, 2025

We encountered the following problem using the TypeCheck:

When there is a schema defining a property and a class providing this property via a getter function, Check and Errors do different things. Check passes while Errors report errors. Here is a mocha test to reproduce:

    test('TypeBox error is different to check', function () {
        const FooSchema = Type.Object({
            foo: Type.String(),
        });
        class Foo {
            _foo: string;
            constructor(foo: string) {
                this._foo = foo;
            }
            get foo() {
                return this._foo;
            }
        }

        const foo = new Foo('bar');
        const compiled = TypeCompiler.Compile(FooSchema);

        assert.ok(compiled.Check(foo));
        const errors = Array.of(compiled.Errors(foo));
        assert.strictEqual(errors.length, 0);
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants