From 57ce9cc1a4803dbeeff2caa0aba9a0274b23c6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E4=BA=8C?= Date: Fri, 5 Nov 2021 00:40:39 +0800 Subject: [PATCH] fix: uncaughtException: this.getWorkspacesAsList(...).find is not a function --- src/services/workspaces/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index 645a0d58..d2487a4a 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -169,11 +169,20 @@ export class Workspace implements IWorkspaceService { /** * Get sorted workspace list + * Async so proxy type is async */ public async getWorkspacesAsList(): Promise { return Object.values(this.workspaces).sort((a, b) => a.order - b.order); } + /** + * Get sorted workspace list + * Sync for internal use + */ + private getWorkspacesAsListSync(): IWorkspace[] { + return Object.values(this.workspaces).sort((a, b) => a.order - b.order); + } + public async get(id: string): Promise { return this.workspaces[id]; } @@ -216,7 +225,7 @@ export class Workspace implements IWorkspaceService { // we add mainWikiID in creation, we fix this value for old existed workspaces // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions if (workspaceToSanitize.isSubWiki && !workspaceToSanitize.mainWikiID) { - const mainWorkspace = (this.getWorkspacesAsList() as unknown as IWorkspace[]).find( + const mainWorkspace = (this.getWorkspacesAsListSync() ?? []).find( (workspaceToSearch) => workspaceToSanitize.mainWikiToLink === workspaceToSearch.wikiFolderLocation, ); if (mainWorkspace !== undefined) {