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

Where parameters do not have relationship typings #65

Open
Ansis100 opened this issue Jun 8, 2023 · 1 comment
Open

Where parameters do not have relationship typings #65

Ansis100 opened this issue Jun 8, 2023 · 1 comment

Comments

@Ansis100
Copy link
Contributor

Ansis100 commented Jun 8, 2023

/**
* an object to be used for a query identifier
* Its keys are the identifier attributes for the where, and the values are the values for that attribute
*/
export interface WhereParamsI {
/** the attribute and values for an identifier */
[attribute: string]: WhereValuesI;
}

The key of WhereParamsI is a string type. This can cause errors that are difficult to debug. For example:

user.findRelationships({
  alias: 'Group',
  where: { target: { grpName: 'Administrators' } },
});

If the model of user groups has a property called groupName then this will fail only at runtime when findRelationships returns zero results.

It would be better if the key of WhereParamsI were typed to be the keys of the related node properties.

@themetalfleece
Copy link
Owner

That's true, but it's a bit difficult to type properly for nested relationships with where. I'll have a fresh look though.
Until then, you can use the satisfies keyword to add some inline type safety, like:

where: {
  name: 'Jason'
} satisfies Partial<UserProperties>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants