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

update type declarations of Schema.index method #10538

Merged
merged 3 commits into from
Aug 9, 2021

Conversation

Raader
Copy link
Contributor

@Raader Raader commented Aug 3, 2021

added proper types to arguments of index method on Schema class.

@Raader Raader changed the title update type declarations for index related fields in Schema type declaration update type declarations of some fields in Schema type declaration Aug 3, 2021
index.d.ts Outdated
@@ -1231,6 +1231,8 @@ declare module 'mongoose' {
type PreSaveMiddlewareFunction<T> = (this: T, next: (err?: CallbackError) => void, opts: SaveOptions) => void | Promise<void>;
type PostMiddlewareFunction<ThisType, ResType = any> = (this: ThisType, res: ResType, next: (err?: CallbackError) => void) => void | Promise<void>;
type ErrorHandlingMiddlewareFunction<ThisType, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: (err?: CallbackError) => void) => void;

type Index = { [key: string]: boolean | number | string | Index }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this | Index here? I don't know of any recursive index definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, changed it to mongodb's index type, It's my first ever pr on a project like this. it is not much but it should help with intellisense.

@Raader Raader changed the title update type declarations of some fields in Schema type declaration update type declarations of Schema.index method Aug 9, 2021
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 5.13.6 milestone Aug 9, 2021
@vkarpov15 vkarpov15 merged commit c1a719d into Automattic:master Aug 9, 2021
@Gotos
Copy link

Gotos commented Sep 24, 2021

This seems to break index creation. mongodb.IndexSpecification doesn't seem to be the right type for the fields parameter. According to the docu and how we used mongoose so far, the fields are "just" an object with the fields that you want to use for the index as keys and values for those set to 1. IndexSpecification is vastly different from that. I think this is likely an error? Or am I missing something?

@Gotos
Copy link

Gotos commented Sep 24, 2021

Nevermind, I just realized this was fixed in 5.13.7. Sorry!

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.

None yet

3 participants