Typescript 将函数标记为async,并将返回作为函数的签名

Typescript 将函数标记为async,并将返回作为函数的签名,typescript,function,asynchronous,promise,signature,Typescript,Function,Asynchronous,Promise,Signature,我刚刚提交了一份PR,有一些反馈我需要处理。我需要将此函数标记为async,并将返回作为函数的签名。有什么指导吗?我敢肯定,将其标记为async只涉及: private async createListEntries(recents: (IRecentWorkspace | IRecentFolder)[], fileService) { 但我不确定第二部分。我不太熟悉打字脚本和函数签名 private createListEntries(recents: (IRecentWorkspace

我刚刚提交了一份PR,有一些反馈我需要处理。我需要将此函数标记为async,并将返回作为函数的签名。有什么指导吗?我敢肯定,将其标记为async只涉及:

private async createListEntries(recents: (IRecentWorkspace | IRecentFolder)[], fileService) {

但我不确定第二部分。我不太熟悉打字脚本和函数签名

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;
            });
        });
    }
private createListEntries(最近的:(IRecentWorkspace | IRecentFolder)[],文件服务){
返回recents.map(最近=>{
让相对路径:字符串;
让完整路径:URI;
让windowOpenable:IWindowOpenable;
让mtime:日期;
如果(isRecentFolder(最近)){
windowOpenable={folderUri:recent.folderUri};
relativePath=recent.label | | this.labelService.getWorkspaceLabel(recent.folderUri,{verbose:true});
fullPath=recent.folderUri;
}否则{
relativePath=recent.label | | this.labelService.getWorkspaceLabel(recent.workspace,{verbose:true});
windowOpenable={workspaceUri:recent.workspace.configPath};
}
返回fileService.resolve(完整路径)。然后((值)=>{
let date=新日期(value.mtime);
mtime=日期;
const options={weekday:'short',year:'numeric',month:'long',day:'numeric',hour:'2位',minute:'2位'};
const lastOpened:string=mtime.toLocaleDateString(未定义,选项);
const{name,parentPath}=splitName(relativePath);
const li=document.createElement('li');
const icon=document.createElement('i');
常量a=document.createElement('a');
const span=document.createElement('span');
const ul=document.querySelector('.recent ul');
icon.title=相对路径;
a、 innerText=名称;
a、 标题=相对路径;
a、 setAttribute('aria-label',localize('welcomePage.openFolderWithPath',“打开路径为{1}的文件夹{0}”,名称,父路径));
a、 href='javascript:void(0)';
a、 addEventListener('click',e=>{
this.telemetryService.publicLog2('workbenchActionExecuted'{
id:“openRecentFolder”,
来自:遥测来自
});
this.hostService.openWindow([windowOpenable],{forceNewWindow:e.ctrlKey | | e.metaKey});
e、 预防默认值();
e、 停止传播();
});
icon.classList.add('themed_icon');
li.appendChild(图标);
li.appendChild(图标);
李.儿童(a);
span.classList.add('path');
span.classList.add('detail');
span.innerText=上次打开;
span.title=相对路径;
李.儿童(span);
ul.儿童(li);
返回李;
});
});
}

不确定您想做什么,但是
异步
函数总是返回一个承诺。您的函数当前返回一个承诺数组。这真的是你想要的吗?