简体   繁体   English

WebStorm错误:表达式语句不是赋值或调用

[英]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:代码工作正常。

You need to change JavaScript Language Version to ES6. 您需要将JavaScript语言版本更改为ES6。 Changing this setting should fix the issue: 更改此设置应解决此问题:

将Javscript版本更改为ES6的设置

In some scenarios, you might need to restart your IDE for the changes to reflect properly. 在某些情况下,您可能需要重新启动IDE才能使更改正确反映。

The problem is that WebStorm will show a warning if that statement isn't doing any of the following within a function: 问题是如果该语句在函数中没有执行以下任何操作,WebStorm将显示​​警告:

  • Calling another function 调用另一个功能
  • Making any sort of assignment 做任何类型的任务
  • Returning a value 返回一个值
  • (There may be more, but those are the ones I know of) (可能会有更多,但那些是我所知道的)

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.

相关问题 表达式语句不是JavaScript代码中的赋值或调用警告 - Expression statement is not assignment or call warning in Javascript code PhpStorm/JavaScript 表达式语句不是赋值或调用 - PhpStorm/JavaScript Expression statement is not assignment or call JsHint:“期望分配或函数调用,而是看到一个表达式”,Switch语句 - JsHint: “Expected an assignment or function call and instead saw an expression”, Switch statement javascript:If语句-预期分配或函数调用,而是看到一个表达式 - javascript: If-statement - Expected an assignment or function call and instead saw an expression IF语句作为JavaScript中的赋值表达式 - IF statement as assignment expression in JavaScript 错误-预期分配或函数调用,而是看到一个表达式 - Error - Expected an assignment or function call and instead saw an expression ReactJS错误:“预期分配或函数调用,而是看到了一个表达式” - ReactJS error: “Expected an assignment or function call and instead saw an expression” 错误:预期分配或函数调用,而是看到一个表达式 - Error: expected an assignment or function call and instead saw an expression 反应错误 [期望赋值或函数调用,而是看到一个表达式] - React error [Expected an assignment or function call and instead saw an expression] 语法错误(预期分配或函数调用,而是看到一个表达式) - Syntax Error (Expected an assignment or function call and instead saw an expression)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM