Skip to content

fix(types): accept $nested.syntax$ in WhereAttributeHash - #13983

Merged
ephys merged 20 commits into
mainfrom
ephys/find-accepts-include-reference
Feb 5, 2022
Merged

ephys merged 20 commits into
mainfrom
ephys/find-accepts-include-reference

Conversation

@ephys

@ephys ephys commented Jan 21, 2022 •

Copy link
Copy Markdown
Member

Pull Request Checklist

Please make sure to review and check all of these items:

  • Have you added new tests to prevent regressions?
  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • [n/a] Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description Of Change

Tiny change that has become possible since we dropped TS < 4.1:
User.findOne({ where: { '$nested.column$': 'blah2' } }) is not reported as an error by TypeScript anymore.

Closes #13288

TODO

  • Check whether $name$ is valid
  • Check whether $include.include.name$ is valid
  • Add tests for nested nested include

@ephys ephys added the typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. label Jan 21, 2022
@ephys ephys self-assigned this Jan 21, 2022
@ephys

ephys commented Jan 21, 2022

Copy link
Copy Markdown
Member Author

TypeScript < 4.4 does not support using Template Literal Types as keys so I had to ts-ignore both the test & the implementation - but it doesn't cause issues in ts < 4.4 and works in ts >= 4.4

We can enable it again on 2022-05-26 when we drop support for TS < 4.4

@ephys

ephys commented Jan 22, 2022

Copy link
Copy Markdown
Member Author

I think with some more black magic we should be able to typecheck include.where too, but I'll keep it for a follow-up PR

User.findOne({
  include: [{
    association: User.associations.group,
    where: {
      // these are not currently type-checked
      test: 'test',
    }
  }],
});

@ephys
ephys marked this pull request as ready for review January 22, 2022 12:28
@ephys
ephys marked this pull request as draft January 22, 2022 14:59
@ephys
ephys marked this pull request as ready for review January 22, 2022 17:22
@ephys
ephys requested review from WikiRik and wbourne0 January 22, 2022 17:22
@ephys ephys mentioned this pull request Jan 28, 2022
4 of 6 tasks
@ephys

ephys commented Jan 31, 2022 •

Copy link
Copy Markdown
Member Author

This PR should also include support for the JSON nested key syntax https://sequelize.org/v4/manual/tutorial/querying.html#nested-key

I can't find the documentation on that syntax for v6. Is it still a thing?

It's looking like it's not and was replaced with sequelize.json

Edit: I've found a place where it was used in order: https://github.com/sequelize/sequelize/blob/main/test/integration/model/json.test.js#L573

Edit 2: And in where, so it's still a thing https://github.com/sequelize/sequelize/blob/main/test/integration/model/json.test.js#L117

We should improve the documentation to reflect this

I wonder if $nested.column$.nested.json.property works. That would impact #13992

@WikiRik

WikiRik commented Jan 31, 2022

Copy link
Copy Markdown
Member

This PR should also include support for the JSON nested key syntax https://sequelize.org/v4/manual/tutorial/querying.html#nested-key

I can't find the documentation on that syntax for v6. Is it still a thing?

It seems that it got lost in #11825

@ephys ephys changed the title fix(types): accept nested columns syntax in WhereAttributeHash fix(types): accept $nested.syntax$ / json.syntax in WhereAttributeHash Jan 31, 2022
@ephys ephys changed the title fix(types): accept $nested.syntax$ / json.syntax in WhereAttributeHash fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash Jan 31, 2022
@ephys ephys changed the title fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash Jan 31, 2022
@ephys ephys changed the title fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash fix(types): accept $nested.syntax$ in WhereAttributeHash Jan 31, 2022
@ephys

ephys commented Jan 31, 2022 •

Copy link
Copy Markdown
Member Author

I'll open a follow-up PR for the json.syntax as the typing I have in mind is a bit complicated

Comment thread types/lib/model.d.ts Resolved
@ephys

ephys commented Feb 2, 2022 •

Copy link
Copy Markdown
Member Author

As the only issue is that the false-positive is still present in TS < 4.4, I think I'll merge this (tomorrow or friday to still leave some time to react). Then we can fix #14038, and then open a follow-up PR that uses typesVersion to provide an alternative typing for TS < 4.4

@WikiRik

WikiRik commented Feb 2, 2022

Copy link
Copy Markdown
Member

Sounds good! We should also publish a new alpha release of v7 after we merged all these typing PRs

@ephys

ephys commented Feb 4, 2022

Copy link
Copy Markdown
Member Author

@WikiRik @allawesome497 if you're ok with the above plan, can I get one of your review approvals? :)

@ephys
ephys merged commit f72bb1e into main Feb 5, 2022
@ephys
ephys deleted the ephys/find-accepts-include-reference branch February 5, 2022 00:54
@ephys ephys mentioned this pull request Feb 6, 2022
@github-actions

github-actions Bot commented Feb 7, 2022

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 7.0.0-alpha.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

aliatsis pushed a commit to creditiq/sequelize that referenced this pull request Jun 2, 2022
vanthome pushed a commit to vanthome/sequelize that referenced this pull request Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released on @v7 typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript complains about $nested.column$ syntax in query where clause.

4 participants