Skip to content

Set mongoose document id property to any - #21856

Merged
aozgaa merged 3 commits into
DefinitelyTyped:masterfrom
simon-xiong-ca:fix-mongoose
Dec 20, 2017
Merged

aozgaa merged 3 commits into
DefinitelyTyped:masterfrom
simon-xiong-ca:fix-mongoose

Conversation

@simon-xiong-ca

Copy link
Copy Markdown
Contributor

The id property can actually be turned off by passing { id: false } when creating a schema.
http://mongoosejs.com/docs/api.html#document_Document-id

The user can then define id and any type so we should allow that.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If changing an existing definition:

@dt-bot

dt-bot commented Nov 30, 2017

Copy link
Copy Markdown
Member

types/mongoose/index.d.ts

to authors (@horiuchi @sindrenm @lukasz-zak). Could you review this PR?
👍 or 👎?

@typescript-bot

typescript-bot commented Dec 5, 2017 •

Copy link
Copy Markdown
Contributor

A definition author has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped!

@typescript-bot typescript-bot added the Unmerged The author did not merge the PR when it was ready. label Dec 5, 2017
@maicss

maicss commented Dec 5, 2017

Copy link
Copy Markdown

Someone merge this ASPS, I'm waiting this for deploy...Thanks.
🙏

Comment thread types/mongoose/index.d.ts
interface MongooseDocumentOptionals {
/** The string version of this documents _id. */
id?: string;
id?: any;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The documentation link says this is string?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is an _id field which is any, was your intention to use that?

@simon-xiong-ca simon-xiong-ca Dec 14, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some user declare id in schema, like: id: number, it conflict. so, I suggest mongoose use mongo _id directly or create itself __id or something like __v, not id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I asked in mongoose:
Automattic/mongoose#5911

The id property is a mongoose getter than can be disabled. When disabled it becomes a regular mongoose document property which can be set to anything.
http://mongoosejs.com/docs/guide.html#id

Comment thread types/mongoose/index.d.ts Outdated
@@ -1144,7 +1144,7 @@ declare module "mongoose" {

interface MongooseDocumentOptionals {
/** The string version of this documents _id. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about this comment here? Since the property isn't necessarily a string anymore, perhaps we could describe it further?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Also because it doesn't necessarily reference the _id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh good point.

@simon-xiong-ca simon-xiong-ca Dec 18, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sindrenm Updated 5a4fc26

@typescript-bot typescript-bot added Author Approved and removed Unmerged The author did not merge the PR when it was ready. labels Dec 18, 2017
@typescript-bot typescript-bot added Other Approved This PR was reviewed and signed-off by a community member. and removed Other Approved This PR was reviewed and signed-off by a community member. labels Dec 18, 2017
@aozgaa
aozgaa merged commit 161184f into DefinitelyTyped:master Dec 20, 2017
@simon-xiong-ca
simon-xiong-ca deleted the fix-mongoose branch January 24, 2018 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants