typescript - 将函数标记为异步并将返回作为函数的签名
问题描述
我刚刚提交了一个 PR,并有一些我需要处理的反馈。我需要将此函数标记为异步并将返回作为函数的签名。有什么指导吗?我很确定将其标记为异步仅涉及:
private async createListEntries(recents: (IRecentWorkspace | IRecentFolder)[], fileService) {
但我不确定第二部分。我对 TypeScript 和函数签名不是很熟悉。
private createListEntries(recents: (IRecentWorkspace | IRecentFolder)[], fileService) {
return recents.map(recent => {
let relativePath: string;
let fullPath: URI;
let windowOpenable: IWindowOpenable;
let mtime: Date;
if (isRecentFolder(recent)) {
windowOpenable = { folderUri: recent.folderUri };
relativePath = recent.label || this.labelService.getWorkspaceLabel(recent.folderUri, { verbose: true });
fullPath = recent.folderUri;
} else {
relativePath = recent.label || this.labelService.getWorkspaceLabel(recent.workspace, { verbose: true });
windowOpenable = { workspaceUri: recent.workspace.configPath };
}
return fileService.resolve(fullPath).then((value) => {
let date = new Date(value.mtime);
mtime = date;
const options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' };
const lastOpened: string = mtime.toLocaleDateString(undefined, options);
const { name, parentPath } = splitName(relativePath);
const li = document.createElement('li');
const icon = document.createElement('i');
const a = document.createElement('a');
const span = document.createElement('span');
const ul = document.querySelector('.recent ul');
icon.title = relativePath;
a.innerText = name;
a.title = relativePath;
a.setAttribute('aria-label', localize('welcomePage.openFolderWithPath', "Open folder {0} with path {1}", name, parentPath));
a.href = 'javascript:void(0)';
a.addEventListener('click', e => {
this.telemetryService.publicLog2<WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification>('workbenchActionExecuted', {
id: 'openRecentFolder',
from: telemetryFrom
});
this.hostService.openWindow([windowOpenable], { forceNewWindow: e.ctrlKey || e.metaKey });
e.preventDefault();
e.stopPropagation();
});
icon.classList.add('themed_icon');
li.appendChild(icon);
li.appendChild(icon);
li.appendChild(a);
span.classList.add('path');
span.classList.add('detail');
span.innerText = lastOpened;
span.title = relativePath;
li.appendChild(span);
ul.appendChild(li);
return li;
});
});
}
解决方案
推荐阅读
- python - 如何根据特定标记拆分数组中的字符串
- python - 在numpy中,如何比较轴中的所有值
- html - 在一个完整的圆形 css 中为任何元素的边框属性设置动画
- c# - 删除 DataRow [] C# 中的一行
- android - Selenium::WebDriver::Error::InvalidElementStateError: 无法将元素设置为“abc”。您是否与正确的元素交互?
- python - 同一模型的 Django-graphene 多种类型
- git - 如何从远程 git 服务器中删除奇怪命名的 ref?
- discord - discord.py 重写 tempmute 命令
- python - 有没有办法使用请求模块下载多个文件
- firebase-cloud-messaging - 您如何修复从 Firebase 云消息传递返回的异常 message_id 或者它是什么意思?