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

updated array push type definition #10546

Merged
merged 9 commits into from
Aug 11, 2021

Conversation

shahriar-shojib
Copy link
Contributor

@shahriar-shojib shahriar-shojib commented Aug 6, 2021

Summary

Array Push Type accepts the T type parameter, it was any

Examples

//typescript
const x = [1,2,3];
x.push('x') // error

//mongoose array
const x = [1,2,3];
x.push('x') // ok
//mongoose array
const x = [ { a: 1 }, { a: 2 } ];
x.push('x') // ok
x.push({ a: 3 }) // no intellisense

index.d.ts Outdated
@@ -1970,10 +1971,10 @@ declare module 'mongoose' {
isMongooseArray: true;

/** Pushes items to the array non-atomically. */
nonAtomicPush(...args: any[]): number;
nonAtomicPush(...args: T[]): number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd make this AnyKeys<T> & AnyObject instead of T[]. Mongoose handles casting, so you don't necessarily have to push an instance of T.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello,
I have made the changes you requested

@vkarpov15 vkarpov15 added this to the 5.13.7 milestone Aug 11, 2021
@vkarpov15 vkarpov15 merged commit 75c3d18 into Automattic:master Aug 11, 2021
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

2 participants