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

Populate typings breaking changes with v6.2.5 #11518

Closed
jeremymelchor opened this issue Mar 11, 2022 · 5 comments
Closed

Populate typings breaking changes with v6.2.5 #11518

jeremymelchor opened this issue Mar 11, 2022 · 5 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@jeremymelchor
Copy link

jeremymelchor commented Mar 11, 2022

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Typings with populate expect a string for the path parameter, before it was typed with any.

If the current behavior is a bug, please provide the steps to reproduce.

Until version 6.2.5, I used populate with an array when populating multiple fields, like .populate(['field1', 'field2'])

Typescript version: 4.5.5

What is the expected behavior?
I don't know if this is wanted, but upgrading to v6.2.5 is a breaking change.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS version: 14

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Mar 11, 2022
@Uzlopak
Copy link
Collaborator

Uzlopak commented Mar 11, 2022

I was checking index.d.ts regarding blame, and I could not find a recent change regarding the typings of populate.

Not saying, that your claim is invalid, but to avoid regressions it is good to know when the regression was introduced.

@Uzlopak
Copy link
Collaborator

Uzlopak commented Mar 11, 2022

In #11503 we already improve the typing of populate. I also mentioned a potential fix for this issue.

@vkarpov15 vkarpov15 added this to the 6.2.6 milestone Mar 11, 2022
@vkarpov15
Copy link
Collaborator

Sorry for the trouble, fix will be in v6.2.6 👍

@Jule-
Copy link

Jule- commented Mar 14, 2022

@vkarpov15 Before I was doing stuff like that:

interface IModel extends Document {
  propA: PopulatedDoc<IModelA, Types.ObjectId>;
  propB: PopulatedDoc<IModelB, Types.ObjectId>;

  createdAt: Date;
  updatedAt: Date;
}

const doc = await Model.findById(myId)
      .populate<{propA: Pick<IModelA, "name">}>("propA", "name")
      .populate<{propB: Pick<IModelB, "name">}>("propB", "name")
      .lean()

And this was compatible with function accepting parameters like that:

function (doc: LeanDocument<IModel & { propA: Pick<IModelA, "name"> }> | null) {
  // ...
}

Now (v6.2.6) I have errors like:

Argument of type '(Omit<Omit<null, "propA"> & { propA: Pick<IModelA, "name">; }, "propB"> & { propB: Pick<IModelB, "name">; }) | undefined' is not assignable to parameter of type 'LeanDocument<IModel & { propA: Pick<IModelA, "name">; }> | null | undefined'.
  Type 'Omit<Omit<null, "propA"> & { propA: Pick<IModelA, "name">; }, "propB"> & { propB: Pick<IModelB, "name">; }' is not assignable to type 'LeanDocument<IModel & { propA: Pick<IModelA, "name">; }> | null | undefined'.
    Type 'Omit<Omit<null, "propA"> & { propA: Pick<IModelA, "name">; }, "propB"> & { propB: Pick<IModelB, "name">; }' is missing the following properties from type 'LeanDocument<IModel & { propA: Pick<IModelA, "name">; }>': createdAt, updatedAt
ts(2345)

I am not sure if it is a regression or if I have to write it differently now!?

@Uzlopak
Copy link
Collaborator

Uzlopak commented Apr 8, 2022

Should be fixed now. If the bug still exists after you updated mongoose, then feel free to reopen an issue.

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
Development

No branches or pull requests

5 participants