我试图理解为什么string以下方法中的返回类型带有红色下划线作为错误:
exportPageAsText(pageNumber: number): string {
(async () => {
const text = await this.pdfViewerService.getPageAsText(pageNumber);
console.log(text);
return text;
})();
}
Run Code Online (Sandbox Code Playgroud)
错误消息如下:A function whose declared type is neither 'void' nor 'any' must return a value.所以我移出return text;范围async并将其放置在后面})();,但这使得text变量无法识别。
然后我想也许是因为方法返回类型应该是 aPromise所以我将签名更改为:
exportPageAsText(pageNumber: number): Promise<string>
Run Code Online (Sandbox Code Playgroud)
但我收到一个新错误说A function whose declared type is neither 'void' nor 'any' must return a value.
有人可以帮助我理解我做错了什么吗?
我写了以下片段:
ngAfterViewInit() {
var svg = d3
.select("svg")
.call(d3.zoom().on("zoom", () => {
svg.attr("transform", d3.event.transform)
}))
.append("g")
}
Run Code Online (Sandbox Code Playgroud)
我知道它d3.event在新版本中已被删除,但是阅读有关如何处理回调中的事件的文档并不能让我理解如何修改它......
有人可以用像我这样的新手可以理解的简单方式向我解释这一点以及如何修复它以使其工作吗?谢谢
我正在尝试通过运行以下命令将我的node版本升级14.17.1:
npm install -g node@14.17.1
它显然成功了,但是当我运行时node -v,我仍然得到旧版本。
我应该采取额外的步骤,还是我做错了?
javascript ×2
typescript ×2
angular ×1
async-await ×1
asynchronous ×1
d3.js ×1
node.js ×1
npm ×1