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

Invalid object produced for optional properties that have multiple nested required properties #122

Open
lo1tuma opened this issue Dec 29, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@lo1tuma
Copy link

lo1tuma commented Dec 29, 2023

Description

Similar to #106 there is another case where fishery produces a value that is incompatible to the defined type constraint.

To Reproduce

interface Bar {
    firstRequiredProperty: string;
    secondRequiredProperty: number;
}

interface Foo {
    optionalProperty?: Bar
}

const fooFactory = Factory.define<Foo>(() => {
    return {}; // I like to have the minimal shape of the interface as the default
});


const value = fooFactory.build({optionalProperty: { firstRequiredProperty: 'foo' } }); // produces type `Foo`, but the actual value does not conform to `Foo` because `optionalProperty.secondRequiredProperty` is missing

Additional context

I think #113 might be related. I’m aware of associations, but as far as I can see associations could only solve the issue when I’m willing to provide a default value for optionalProperty, which I do not want.

@lo1tuma lo1tuma added the bug Something isn't working label Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant