From d477cb8045929f1701324a417941c57093cdb02e Mon Sep 17 00:00:00 2001 From: cybai Date: Sat, 28 Aug 2021 00:33:42 +0900 Subject: [PATCH] frontend: Upgrade TypeScript from 2.9.2 to 4.4.2 (#387) * Upgrade TS from 2.9.2 to 4.4.2 * Avoid mutating a readonly array `list` is a readonly array but `sort` will mutate the array in-place. In newer version of TS, it can catch this unexpected behavior. To avoid mutating a readonly array, we can sort with a new array with either `[...list]` or `list.slice()`. * Fix arguments of `window.location.reload` The `reload` function type definition in `lib.dom.d.ts` takes 0 arguments now. So, we cannot pass a boolean to it. Also, based on the documentation on MDN, Firefox is the only browser who supports passing a `forceForget` boolean to `reload` function. So, I wonder it should be fine to remove the boolean argument and align the behavior to other browsers. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Location/reload --- frontend/package.json | 2 +- frontend/src/Connection.ts | 2 +- frontend/src/common/helpers.ts | 4 +++- frontend/yarn.lock | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 933bf61..7bbe166 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -44,7 +44,7 @@ "tslint": "^6.1.1", "tslint-config-prettier": "^1.18.0", "tslint-plugin-prettier": "^2.3.0", - "typescript": "^2.9.2" + "typescript": "^4.4.2" }, "lint-staged": { "src/**/*.{ts,tsx,json,css}": [ diff --git a/frontend/src/Connection.ts b/frontend/src/Connection.ts index c8fdcde..23ddb1e 100644 --- a/frontend/src/Connection.ts +++ b/frontend/src/Connection.ts @@ -487,7 +487,7 @@ export class Connection { this.clean(); // Force reload from the server - setTimeout(() => window.location.reload(true), 3000); + setTimeout(() => window.location.reload(), 3000); } private clean() { diff --git a/frontend/src/common/helpers.ts b/frontend/src/common/helpers.ts index e89f3df..ba2aa50 100644 --- a/frontend/src/common/helpers.ts +++ b/frontend/src/common/helpers.ts @@ -119,7 +119,9 @@ export class NumStats { let sum = 0; - for (const n of list.sort((a, b) => a - b).slice(extremes, -extremes)) { + for (const n of [...list] + .sort((a, b) => a - b) + .slice(extremes, -extremes)) { sum += n; } diff --git a/frontend/yarn.lock b/frontend/yarn.lock index cb8103b..3e1d81f 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -9467,10 +9467,10 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^2.9.2: - version "2.9.2" - resolved "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" - integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w== +typescript@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86" + integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ== uglify-es@^3.3.4: version "3.3.9"