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

TypeScript return type from $relatedQuery is not optional for optional relation #2355

Open
ryan-gray-db opened this issue Jan 24, 2023 · 0 comments
Labels

Comments

@ryan-gray-db
Copy link

I have a model with a relation that's optional, however when I use $relatedQuery to get the relation, the return type is not optional. I put together a small project to demonstrate!

Snippet from project:

const Example = async () => {
    const customer = await Customer.query().findById("123").throwIfNotFound();
    /**
     * The program relation on customer is an optional relation. I would expect this to be returned from $relatedQuery
     * as optional, but the typing is just Program
     */
    const program = await customer.$relatedQuery("program");
    console.log(program.id);
}

Example project:
https://github.com/ryan-gray-db/objection-relation

@lehni lehni added the typings label Apr 15, 2023
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