Bra*_*rad 5 javascript superagent ecmascript-6 eslint es6-promise
我正在尝试使用 Webpack 1.13.12 和 eslint 3.11.0 和 eslint-plugin-promise 3.4.0。我正在尝试使用这个问题的答案来让 Superagent 生成 Web 服务调用的结果。
import agent from 'superagent';
require('superagent-as-promised')(agent);
import Promise from 'promise';
const API_URL = 'http://localhost/services/merchant';
export function createVendorCall() {
const responsePromise = yield Promise.resolve(agent.put(`${API_URL}/create`));
let response = responsePromise.next();
return response.body;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试对此进行检查时,eslint 抱怨说The keyword 'yield' is reserved. 我已尝试require-yield在 .eslintrc.json 文件中设置为 0,但它仍然不会 lint。使用内联注释禁用 eslint 也不起作用。
我应该怎么办?我是否以错误的方式使用 Superagent,或者是否有我必须禁用的规则?
编辑:这个问题被标记为这个问题的重复。然而,这个问题没有使用 linter,并且有不同的错误消息。这里的问题是 eslint 将看似有效的语法标记为错误。
尝试在函数名称中添加 a,*这样它将成为一个生成器:
export function *createVendorCall() {
const responsePromise = yield Promise.resolve(agent.put(`${API_URL}/create`));
let response = responsePromise.next();
return response.body;
}
Run Code Online (Sandbox Code Playgroud)
yield只能在发电机中使用。
| 归档时间: |
|
| 查看次数: |
12612 次 |
| 最近记录: |