From 1d0bb180f413bed73979df86a3abc8b050f0fdda Mon Sep 17 00:00:00 2001 From: Tiago Santos Da Silva Date: Mon, 4 Oct 2021 06:44:30 -0300 Subject: [PATCH] Typing adjustment - 1354 (#1416) * refactor: adjusting typing * fix: Correction of some typings with unknown --- webapp/src/octoClient.ts | 12 ++++++------ webapp/src/pages/registerPage.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/webapp/src/octoClient.ts b/webapp/src/octoClient.ts index c5424427b..e19681510 100644 --- a/webapp/src/octoClient.ts +++ b/webapp/src/octoClient.ts @@ -45,7 +45,7 @@ class OctoClient { this.serverUrl = serverUrl } - private async getJson(response: Response, defaultValue: any): Promise { + private async getJson(response: Response, defaultValue: unknown): Promise { // The server may return null or malformed json try { const value = await response.json() @@ -93,7 +93,7 @@ class OctoClient { return json } - async register(email: string, username: string, password: string, token?: string): Promise<{code: number, json: any}> { + async register(email: string, username: string, password: string, token?: string): Promise<{code: number, json: {error?: string}}> { const path = '/api/v1/register' const body = JSON.stringify({email, username, password, token}) const response = await fetch(this.getBaseURL() + path, { @@ -101,11 +101,11 @@ class OctoClient { headers: this.headers(), body, }) - const json = (await this.getJson(response, {})) + const json = (await this.getJson(response, {})) as {error?: string} return {code: response.status, json} } - async changePassword(userId: string, oldPassword: string, newPassword: string): Promise<{code: number, json: any}> { + async changePassword(userId: string, oldPassword: string, newPassword: string): Promise<{code: number, json: {error?: string}}> { const path = `/api/v1/users/${encodeURIComponent(userId)}/changepassword` const body = JSON.stringify({oldPassword, newPassword}) const response = await fetch(this.getBaseURL() + path, { @@ -113,7 +113,7 @@ class OctoClient { headers: this.headers(), body, }) - const json = (await this.getJson(response, {})) + const json = (await this.getJson(response, {})) as {error?: string} return {code: response.status, json} } @@ -236,7 +236,7 @@ class OctoClient { // Hydrate is important, as it ensures that each block is complete to the current model const fixedBlocks = OctoUtils.hydrateBlocks(blocks) - // TODO: Remove this fixup code + // !TODO: Remove this fixup code for (const block of fixedBlocks) { if (!block.fields) { block.fields = {} diff --git a/webapp/src/pages/registerPage.tsx b/webapp/src/pages/registerPage.tsx index d45d3700a..a78a91a4c 100644 --- a/webapp/src/pages/registerPage.tsx +++ b/webapp/src/pages/registerPage.tsx @@ -33,7 +33,7 @@ const RegisterPage = React.memo(() => { } else if (response.code === 401) { setErrorMessage('Invalid registration link, please contact your administrator') } else { - setErrorMessage(response.json?.error) + setErrorMessage(`${response.json?.error}`) } }