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

SchemaDate types not matching jsdoc types / accepted types #10529

Closed
hasezoey opened this issue Aug 1, 2021 · 1 comment
Closed

SchemaDate types not matching jsdoc types / accepted types #10529

hasezoey opened this issue Aug 1, 2021 · 1 comment
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@hasezoey
Copy link
Collaborator

hasezoey commented Aug 1, 2021

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

What is the current behavior?
SchemaDate jsdoc & examples list that accepted types are Number | String

mongoose/lib/schema/date.js

Lines 118 to 157 in 80245ed

/**
* Declares a TTL index (rounded to the nearest second) for _Date_ types only.
*
* This sets the `expireAfterSeconds` index option available in MongoDB >= 2.1.2.
* This index type is only compatible with Date types.
*
* ####Example:
*
* // expire in 24 hours
* new Schema({ createdAt: { type: Date, expires: 60*60*24 }});
*
* `expires` utilizes the `ms` module from [guille](https://github.com/guille/) allowing us to use a friendlier syntax:
*
* ####Example:
*
* // expire in 24 hours
* new Schema({ createdAt: { type: Date, expires: '24h' }});
*
* // expire in 1.5 hours
* new Schema({ createdAt: { type: Date, expires: '1.5h' }});
*
* // expire in 7 days
* const schema = new Schema({ createdAt: Date });
* schema.path('createdAt').expires('7d');
*
* @param {Number|String} when
* @added 3.0.0
* @return {SchemaType} this
* @api public
*/
SchemaDate.prototype.expires = function(when) {
if (!this._index || this._index.constructor.name !== 'Object') {
this._index = {};
}
this._index.expires = when;
utils.expires(this._index);
return this;
};

but types say its number | Date (not number | string)

mongoose/index.d.ts

Lines 1660 to 1661 in c36bd64

/** Defines a TTL index on this path. Only allowed for dates. */
expires?: number | NativeDate;

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


PS: is it correct to not include SchemaDate (and others) in the documentation? there i could only find SchemaDateOptions under API (and SchemaDateOptions does not have the examples / accepted types from SchemaDate)

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Aug 2, 2021
@vkarpov15
Copy link
Collaborator

Re: including SchemaDate in documentation, that's worth discussing more. We explicitly exclude them because we don't want to imply that users should be creating SchemaDate instances - most users shouldn't have to be aware of SchemaDate.

@vkarpov15 vkarpov15 modified the milestones: 5.13.6, 5.13.7 Aug 3, 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
Development

No branches or pull requests

3 participants