Пометьте функцию как asyn c и получите возврат в качестве сигнатуры функции - PullRequest
0 голосов
/ 18 марта 2020

Я только что отправил пиар и получил отзыв, о котором мне нужно позаботиться. Мне нужно пометить эту функцию как asyn c и получить возврат в качестве сигнатуры функции. Любое руководство? Я почти уверен, что пометить его как asyn c просто значит:

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;
            });
        });
    }
...