Skip to content

Commit

Permalink
deps: update to typescript 4.1.2 (#11690)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Nov 24, 2020
1 parent 8c14a60 commit 38c534c
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 25 deletions.
3 changes: 3 additions & 0 deletions build/gh-pages-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class GhPagesApp {
});
}

/**
* @return {Promise<void>}
*/
deploy() {
return new Promise((resolve, reject) => {
ghPages.publish(this.distDir, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class UnusedBytes extends Audit {
* Estimates the number of bytes this network record would have consumed on the network based on the
* uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable.
*
* @param {LH.Artifacts.NetworkRequest=} networkRecord
* @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
* @param {number} totalBytes Uncompressed size of the resource
* @param {LH.Crdp.Network.ResourceType=} resourceType
* @return {number}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/unminified-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UnminifiedCSS extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts.CSSStyleSheetInfo} stylesheet
* @param {LH.Artifacts.NetworkRequest=} networkRecord
* @param {LH.Artifacts.NetworkRequest|undefined} networkRecord
* @param {string} pageUrl
* @return {{url: string, totalBytes: number, wastedBytes: number, wastedPercent: number}}
*/
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/charset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Audits a page to ensure charset it configured properly.
* It must be defined within the first 1024 bytes of the HTML document, defined in the HTTP header, or the document source must start with a BOM.
*
* @see: https://github.com/GoogleChrome/lighthouse/issues/10023
* @see https://github.com/GoogleChrome/lighthouse/issues/10023
*/
'use strict';

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class Config {

/**
* @param {string} path
* @param {{}=} options
* @param {{}|undefined} options
* @param {Array<string>} coreAuditList
* @param {string=} configDir
* @return {LH.Config.GathererDefn}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class Fetcher {
iframe.src = src;
iframe.onload = iframe.onerror = () => {
iframe.remove();
delete iframe.onload;
delete iframe.onerror;
iframe.onload = null;
iframe.onerror = null;
};
document.body.appendChild(iframe);
}
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/gather/gatherers/image-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function getHTMLImages(allElements) {
cssComputedPosition: getPosition(element, computedStyle),
isCss: false,
isPicture,
// @ts-expect-error: loading attribute not yet added to HTMLImageElement definition.
loading: element.loading,
resourceSize: 0, // this will get overwritten below
usesObjectFit: ['cover', 'contain', 'scale-down', 'none'].includes(
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/lib/dependency-graph/simulator/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ class Simulator {

/**
* @param {Node} node
* @return {NodeTimingIntermediate}
* @return {Required<NodeTimingIntermediate>}
*/
_getTimingData(node) {
const timingData = this._nodeTimings.get(node);
if (!timingData) throw new Error(`Unable to get timing data for node ${node.id}`);
// @ts-expect-error - Allow consumers to assume all values are defined.
return timingData;
}

Expand Down Expand Up @@ -405,7 +406,8 @@ class Simulator {
_computeFinalNodeTimings() {
/** @type {Array<[Node, LH.Gatherer.Simulation.NodeTiming]>} */
const nodeTimingEntries = [];
for (const [node, timing] of this._nodeTimings) {
for (const node of this._nodeTimings.keys()) {
const timing = this._getTimingData(node);
nodeTimingEntries.push([node, {
startTime: timing.startTime,
endTime: timing.endTime,
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/lib/i18n/swap-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function swapLocale(lhr, requestedLocale) {
const {icuMessagePaths} = lhr.i18n;
const missingIcuMessageIds = [];

if (!icuMessagePaths) throw new Error('missing icuMessagePaths');

for (const [i18nId, icuMessagePath] of Object.entries(icuMessagePaths)) {
for (const instance of icuMessagePath) {
// The path that _formatPathAsString() generated.
Expand Down
5 changes: 3 additions & 2 deletions lighthouse-core/lib/lh-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ class LighthouseError extends Error {
*/
static fromProtocolMessage(method, protocolError) {
// extract all errors with a regex pattern to match against.
const protocolErrors = Object.values(LighthouseError.errors).filter(e => e.pattern);
// if we find one, use the friendly LighthouseError definition
const matchedErrorDefinition = protocolErrors.find(e => e.pattern.test(protocolError.message));
const matchedErrorDefinition = Object.values(LighthouseError.errors)
.filter(e => e.pattern)
.find(e => e.pattern && e.pattern.test(protocolError.message));
if (matchedErrorDefinition) {
return new LighthouseError(matchedErrorDefinition);
}
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/report/html/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Util {
// into 'debugdata' (LHR ≥5.0).
// @ts-expect-error tsc rightly flags that these values shouldn't occur.
if (audit.details.type === undefined || audit.details.type === 'diagnostic') {
// @ts-expect-error details is of type never.
audit.details.type = 'debugdata';
}

Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/scripts/generate-bundlephobia-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

const fs = require('fs');
const path = require('path');
const getPackageVersionList = require('bundle-phobia-cli').fetchPackageStats.getPackageVersionList;
const fetchPackageStats = require('bundle-phobia-cli').fetchPackageStats.fetchPackageStats;
const {getPackageVersionList, fetchPackageStats} = require('bundle-phobia-cli').fetchPackageStats;
const databasePath = path.join(__dirname,
'../lib/large-javascript-libraries/bundlephobia-database.json');

Expand Down
14 changes: 10 additions & 4 deletions lighthouse-core/scripts/lantern/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const path = require('path');

/**
* @typedef EstimateEvaluationSummary
* @property {LanternEvaluation[]} evaluations
* @property {LanternEvaluation[]} [evaluations]
* @property {number} p50
* @property {number} p90
* @property {number} p95
Expand Down Expand Up @@ -113,7 +113,10 @@ module.exports = {
* @return {(LanternEvaluation & LanternSiteDefinition)|null}
*/
evaluateSite(site, expectedMetrics, actualMetrics, metric, lanternMetric) {
const expected = Math.round(expectedMetrics[metric]);
const expectedRaw = expectedMetrics[metric];
if (expectedRaw === undefined) return null;

const expected = Math.round(expectedRaw);
if (expected === 0) return null;

const actual = Math.round(actualMetrics[lanternMetric]);
Expand All @@ -135,18 +138,21 @@ module.exports = {
* @param {LanternSiteDefinition[]} entries
* @param {keyof TargetMetrics} metric
* @param {keyof LanternMetrics} lanternMetric
* @param {'lantern'|'baseline'} [lanternOrBaseline]
* @param {'lantern'|'baseline'} lanternOrBaseline
* @return {EstimateEvaluationSummary}
*/
evaluateAccuracy(entries, metric, lanternMetric, lanternOrBaseline = 'lantern') {
const evaluations = [];

const percentErrors = [];
for (const entry of entries) {
const actualMetrics = entry[lanternOrBaseline];
if (!actualMetrics) throw new Error(`No metrics for ${metric} ${lanternMetric} ${lanternOrBaseline}`);

const evaluation = this.evaluateSite(
entry,
entry.wpt3g,
entry[lanternOrBaseline],
actualMetrics,
metric,
lanternMetric
);
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/scripts/lantern/print-correlations.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ function evaluateAndPrintAccuracy(metric, lanternMetric) {
)}`.padEnd(30),
];

allEvaluations.push(...actualAccuracy.evaluations);
baselineEvaluations.push(...baselineAccuracy.evaluations);
if (actualAccuracy.evaluations) allEvaluations.push(...actualAccuracy.evaluations);
if (baselineAccuracy.evaluations) baselineEvaluations.push(...baselineAccuracy.evaluations);

if (lanternMetric.includes('roughEstimate')) {
console.log(...strings);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"pretty-json-stringify": "^0.0.2",
"puppeteer": "^1.19.0",
"terser": "^4.2.0",
"typescript": "3.9.7",
"typescript": "4.1.2",
"webtreemap-cdt": "^3.0.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion types/lhr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ declare global {
/** Execution timings for the Lighthouse run */
timing: Result.Timing;
/** The record of all formatted string locations in the LHR and their corresponding source values. */
i18n: {rendererFormattedStrings: I18NRendererStrings, icuMessagePaths: IcuMessagePaths};
i18n: {rendererFormattedStrings: I18NRendererStrings, icuMessagePaths?: IcuMessagePaths};
/** An array containing the result of all stack packs. */
stackPacks?: Result.StackPack[];
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8061,10 +8061,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
typescript@4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.2.tgz#6369ef22516fe5e10304aae5a5c4862db55380e9"
integrity sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==

uglify-js@^3.1.4:
version "3.4.9"
Expand Down

0 comments on commit 38c534c

Please sign in to comment.