From 4b0fd8bc30389e9b7ba176649c1e119e0446e071 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Tue, 31 Mar 2020 17:42:32 +0100 Subject: [PATCH] chore: upgrade to TypeScript 3.7 (#5562) TypeScript seems to struggle to understand `Promise.all` when the items in the array return different types. If we were authoring in TS we could fix this with TS generics (`Promise.all(...)`) but for now we can typecast the result. We'll fix this properly when we author in TS. --- lib/Coverage.js | 3 ++- lib/FrameManager.js | 4 +++- lib/WebSocketTransport.js | 4 ---- package.json | 2 +- utils/doclint/check_public_api/JSBuilder.js | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Coverage.js b/lib/Coverage.js index 5f88c10e9a1..23bae694ddf 100644 --- a/lib/Coverage.js +++ b/lib/Coverage.js @@ -137,7 +137,7 @@ class JSCoverage { async stop() { assert(this._enabled, 'JSCoverage is not enabled'); this._enabled = false; - const [profileResponse] = await Promise.all([ + const result = await Promise.all([ this._client.send('Profiler.takePreciseCoverage'), this._client.send('Profiler.stopPreciseCoverage'), this._client.send('Profiler.disable'), @@ -146,6 +146,7 @@ class JSCoverage { helper.removeEventListeners(this._eventListeners); const coverage = []; + const profileResponse = /** @type Protocol.Profiler.takePreciseCoverageReturnValue */ (result[0]); for (const entry of profileResponse.result) { let url = this._scriptURLs.get(entry.scriptId); if (!url && this._reportAnonymousScripts) diff --git a/lib/FrameManager.js b/lib/FrameManager.js index fea03dc2c03..1dd2bbd5e33 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -56,10 +56,12 @@ class FrameManager extends EventEmitter { } async initialize() { - const [,{frameTree}] = await Promise.all([ + const result = await Promise.all([ this._client.send('Page.enable'), this._client.send('Page.getFrameTree'), ]); + + const {frameTree} = /** @type Protocol.Page.getFrameTreeReturnValue*/ (result[1]); this._handleFrameTree(frameTree); await Promise.all([ this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }), diff --git a/lib/WebSocketTransport.js b/lib/WebSocketTransport.js index ff951e15aa6..065a8eb9b3e 100644 --- a/lib/WebSocketTransport.js +++ b/lib/WebSocketTransport.js @@ -30,10 +30,6 @@ class WebSocketTransport { maxPayload: 256 * 1024 * 1024, // 256Mb }); - /* error that WebSocket is not assignable to type WebSocket - * due to a misisng dispatchEvent() method which the ws library - * does not implement and we do not need - */ ws.addEventListener('open', () => resolve(new WebSocketTransport(ws))); ws.addEventListener('error', reject); }); diff --git a/package.json b/package.json index de264fde9d8..f26678fa535 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "pixelmatch": "^4.0.2", "pngjs": "^3.3.3", "text-diff": "^1.0.1", - "typescript": "3.6.5" + "typescript": "3.7.5" }, "browser": { "./lib/BrowserFetcher.js": false, diff --git a/utils/doclint/check_public_api/JSBuilder.js b/utils/doclint/check_public_api/JSBuilder.js index d56e4381a63..065dc818c88 100644 --- a/utils/doclint/check_public_api/JSBuilder.js +++ b/utils/doclint/check_public_api/JSBuilder.js @@ -160,7 +160,7 @@ function checkSources(sources) { properties.push(...innerType.properties); innerTypeNames.push(innerType.name); } - if (innerTypeNames.length === 1 && innerTypeNames[0] === 'void') + if (innerTypeNames.length === 0 || innerTypeNames.length === 1 && innerTypeNames[0] === 'void') return new Documentation.Type(type.symbol.name); return new Documentation.Type(`${type.symbol.name}<${innerTypeNames.join(', ')}>`, properties); }