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

fix(index.d.ts) treat _id like other fields in $project #11102

Merged
merged 2 commits into from
Dec 20, 2021
Merged

fix(index.d.ts) treat _id like other fields in $project #11102

merged 2 commits into from
Dec 20, 2021

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Dec 15, 2021

Fix #11088
Fix #11099

Changed type to

$project: { _id?: 0 | false; [field: string]: any } | {_id: 1 | true}

✔️ OK

{
  $project: {
    _id: 1,
  }
}

✔️ OK

{
  $project: {
    _id: 0,
    someField: 1
  }
}

❌ Error

{
  $project: {
    _id: 1,
    someField: 1
  }
}

@Uzlopak
Copy link
Collaborator

Uzlopak commented Dec 15, 2021

_id can also be null and could be an issue if strictNullChecks is true.

@rpenido
Copy link
Contributor Author

rpenido commented Dec 15, 2021

_id can also be null and could be an issue if strictNullChecks is true.

Both cases below also work because of the ? in _id? type declaration

{
  someField: 1
}
{
  _id: undefined,
  someField: 1
}

Was that your concern? Could you please clarify?

Thank you!

@Uzlopak
Copy link
Collaborator

Uzlopak commented Dec 15, 2021

You are right. This is not an issue. Good Work.

@intenser
Copy link

intenser commented Dec 15, 2021

$project: { _id?: 0 | false; [field: string]: any } | {_id: 1 | true}

I'm not sure that is a correct definition. MongoDB allows a lot of variations for _id:

{$project:{_id: "some text"}}

{$project:{_id: "$referOtherField"}}

{$project:{_id: {$concat: ["$firstName", "$lastName"]}}} // expressions

Or even:

{ $project: {
    _id: {
      $cond: {
        if: { $eq: ['server', '$deviceType'] },
        then: '$$REMOVE',
        else: '$_id'
      }
    },
    deviceType: 1
}}

@rpenido
Copy link
Contributor Author

rpenido commented Dec 15, 2021

I agree with you.

So I don't think that we should treat _id differently.

@rpenido rpenido changed the title fix(index.d.ts) allow $project with only {_id: 1} fix(index.d.ts) treat _id like other fields in $project Dec 15, 2021
@tbhaxor
Copy link
Contributor

tbhaxor commented Dec 15, 2021

This would work. Can we merge this and release it in next version

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@vkarpov15 vkarpov15 added this to the 6.1.3 milestone Dec 20, 2021
@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Dec 20, 2021
@vkarpov15 vkarpov15 merged commit c45aa1f into Automattic:master Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
5 participants