[英]WebStorm error: expression statement is not assignment or call
I'm using WebStorm and I'm getting an error that I can't understand. 我正在使用WebStorm,我收到一个我无法理解的错误。 Node.js + MongoDB.
Node.js + MongoDB。
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect(' mongodb://localhost:27017/TodoApp');
var Todo = mongoose.model('Todo', {
text: {
type: String
},
completed: {
type: Boolean
},
completedAt: {
type: Number
}
});
var newTodo = new Todo({
text: 'Cook dinner'
});
The problem is in this block: 问题出在这个块中:
newTodo.save().then((doc) => {
console.log('Saved todo', doc);
}, (e) => {
console.log('Unable to save todo')
})
PS: The code works fine. PS:代码工作正常。
The problem is that WebStorm will show a warning if that statement isn't doing any of the following within a function: 问题是如果该语句在函数中没有执行以下任何操作,WebStorm将显示警告:
In other words, WebStorm views that function as unnecessary and tries to help you catch unused code. 换句话说, WebStorm视图的功能是不必要的,并试图帮助您捕获未使用的代码。
For example this will show the warning: 例如,这将显示警告:
const arr = [1, 2];
const willShowWarning = arr.map(num => {
num + 1;
});
Adding a return will take the warning away: 添加退货将取消警告:
const arr = [1, 2];
const willNotShowWarning = arr.map(num => {
return num + 1;
});
The answer is not to change WebStorm settings. 答案不是改变WebStorm设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.