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

Typescript IntelliSense not working for model.updateOne second parameter #14090

Closed
2 tasks done
Trystan-SA opened this issue Nov 17, 2023 · 3 comments · Fixed by #14123
Closed
2 tasks done

Typescript IntelliSense not working for model.updateOne second parameter #14090

Trystan-SA opened this issue Nov 17, 2023 · 3 comments · Fixed by #14123
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@Trystan-SA
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.0.1

Node.js version

18.18.2

MongoDB server version

7.0.3 Community

Typescript version (if applicable)

5.2.2

Description

Typescripts interface works for model.findOne({ /* Autocompletion Working */ }) but not for the second parameter of model.updateOne({ /* Autocompletion Working */}, { /* Autocompletion missing */ })

Steps to Reproduce

import {Schema, model} from 'mongoose'

export interface IRoles {
    name: string;
    permissions: [string];
    inherit_from: IRoles;
}
export const RolesSchema = new Schema<IRoles>({
    name: {type: String, required: true},
    permissions: [{type: String}],
    inherit_from: {type: Schema.Types.ObjectId, ref: 'Roles'}
}, {timestamps: true})


export const RolesModel = model<IRoles>('Roles', RolesSchema)


RolesModel.updateOne({name: '123'}, { /* Autocompletion not working here */ })

RolesModel.findOne({name: '123'})

I'm only get the default IntelliSense
image

Vscode seems to get the Inferred type, the second parameter type is UpdateWithAggregationPipeline | UpdateQuery<IRoles>
image

Expected Behavior

I should get the same autocompletion as the first updateOne parameter.

@vkarpov15
Copy link
Collaborator

What intellisense do you expect to see? The screenshot you pasted shows MongoDB update operators, which is reasonably correct.

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Nov 21, 2023
@Trystan-SA
Copy link
Author

Hey. I expect to see my schema elements, in this case name permissions inherit_from so i could get autocomplete by typing

RolesModel.updateOne({name: '123'}, {permissions: ['admin', 'read']})

Were permissions get autocompleted (and so I could know it expect an array of strings).

@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Nov 25, 2023
@vkarpov15 vkarpov15 added this to the 8.0.2 milestone Nov 25, 2023
@vkarpov15
Copy link
Collaborator

We generally don't debug IDE autocomplete issues, but we will take a quick look at this one.

vkarpov15 added a commit that referenced this issue Nov 26, 2023
types: make property names show up in intellisense for UpdateQuery
@vkarpov15 vkarpov15 reopened this Nov 26, 2023
@vkarpov15 vkarpov15 modified the milestones: 8.0.2, 7.6.6 Nov 26, 2023
@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Nov 26, 2023
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

Successfully merging a pull request may close this issue.

2 participants