简体   繁体   中英

WebStorm to autocomplete Mongoose schema fields

Let's say I'm using the standard Mongoose model:

Creating a schema

const userSchema    = new mongoose.Schema({
  displayName     : {type: String, required: true},
  phoneNumber     : {type: String},
});

Then connect it to a model:

const UserModel = mongooseClient.model('User', userSchema);

I'd like WebStorm to autocomplete me in the following way:

const myUser = new UserModel();
myUser.disp // should suggest 'displayName'

How do I accomplish it?

Providing completion for your schema fields/methods requires adding special support for Mongooze, as objects generated in runtime can't be resolved by static code analysis. We have a feature request for this, please feel free to vote: WEB-22317 .

For now, using JSDoc to annotate objects is the only way to go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM