Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update to typescript 3.5.3 #9357

Merged
merged 2 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lighthouse-core/computed/network-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const NetworkRecords = require('./network-records.js');
class NetworkAnalysis {
/**
* @param {Array<LH.Artifacts.NetworkRequest>} records
* @return {Omit<LH.Artifacts.NetworkAnalysis, 'throughput'>}
* @return {StrictOmit<LH.Artifacts.NetworkAnalysis, 'throughput'>}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caused by microsoft/TypeScript#30552. See that thread for the drama over strictness :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, that is some good drama. I personally found microsoft/TypeScript#30825 more enjoyable to follow :)

Kinda nuts it's a useless version of Omit for me, I got excited for a second I wouldn't have to copy this everywhere

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, that is some good drama. I personally found microsoft/TypeScript#30825 more enjoyable to follow :)

oh yeah, whoops, that's a way better link

*/
static computeRTTAndServerResponseTime(records) {
// First pass compute the estimated observed RTT to each origin's servers.
Expand Down
8 changes: 3 additions & 5 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,9 @@ function cleanFlagsForSettings(flags = {}) {
const settings = {};

for (const key of Object.keys(flags)) {
// @ts-ignore - intentionally testing some keys not on defaultSettings to discard them.
if (typeof constants.defaultSettings[key] !== 'undefined') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to remember being very careful about in vs undefined for constants.defaultSettings but that might have just been on the delete vs. = undefined side.

the PR (#4960) doesn't seem to suggest there was anything special about this, and in should be even more inclusive for our purposes, so we're probably fine 🤷‍♂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to remember being very careful about in vs undefined for constants.defaultSettings but that might have just been on the delete vs. = undefined side.

yeah, I was thinking since it's just the constants this should be ok (we won't have set anything to undefined to try to mark them as unset), but I can also switch it to an undefined check. It doesn't help the compiler either way since we have to do @ts-ignore on the next line regardless :)

// Cast since key now must be able to index both Flags and Settings.
const safekey = /** @type {Extract<keyof LH.Flags, keyof LH.Config.Settings>} */ (key);
settings[safekey] = flags[safekey];
if (key in constants.defaultSettings) {
// @ts-ignore tsc can't yet express that key is only a single type in each iteration, not a union of types.
settings[key] = flags[key];
}
}

Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ class GatherRunner {
for (const [gathererName, phaseResultsPromises] of resultsEntries) {
try {
const phaseResults = await Promise.all(phaseResultsPromises);
// Take last defined pass result as artifact.
// Take the last defined pass result as artifact. If none are defined, the undefined check below handles it.
const definedResults = phaseResults.filter(element => element !== undefined);
const artifact = definedResults[definedResults.length - 1];
// Typecast pretends artifact always provided here, but checked below for top-level `throw`.
gathererArtifacts[gathererName] = /** @type {NonVoid<PhaseResult>} */ (artifact);
// @ts-ignore tsc can't yet express that gathererName is only a single type in each iteration, not a union of types.
gathererArtifacts[gathererName] = artifact;
} catch (err) {
// Return error to runner to handle turning it into an error audit.
gathererArtifacts[gathererName] = err;
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/lantern-trace-saver.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function convertNodeTimingsToTrace(nodeTimings) {
if (startTime === endTime) endTime += 0.3;

const requestData = {requestId: requestId.toString(), frame};
/** @type {Omit<LH.TraceEvent, 'name'|'ts'|'args'>} */
/** @type {StrictOmit<LH.TraceEvent, 'name'|'ts'|'args'>} */
const baseRequestEvent = {...baseEvent, ph: 'I', s: 't', dur: 0};

const sendRequestData = {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/report/html/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class ReportUIFeatures {
*/
onCopy(e) {
// Only handle copy button presses (e.g. ignore the user copying page text).
if (this._copyAttempt) {
if (this._copyAttempt && e.clipboardData) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this error for a long time in VS Code. Did only newer TS emit this error? maybe my editor is set to typescript@next ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this error for a long time in VS Code. Did only newer TS emit this error? maybe my editor is set to typescript@next ...

they change the browser definitions from time to time, so it's possible. If you do the "Select typescript version" command in vs code do you have "Use VS Code's version" selected?

// We want to write our own data to the clipboard, not the user's text selection.
e.preventDefault();
e.clipboardData.setData('text/plain', JSON.stringify(this.json, null, 2));
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ class Runner {
// to prevent consumers from unnecessary type assertions.
const requiredArtifacts = audit.meta.requiredArtifacts
.reduce((requiredArtifacts, artifactName) => {
requiredArtifacts[artifactName] = artifacts[artifactName];
const requiredArtifact = artifacts[artifactName];
// @ts-ignore tsc can't yet express that artifactName is only a single type in each iteration, not a union of types.
requiredArtifacts[artifactName] = requiredArtifact;
return requiredArtifacts;
}, /** @type {LH.Artifacts} */ ({}));
const product = await audit.audit(requiredArtifacts, auditContext);
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-core/scripts/update-report-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async function update(artifactName) {
throw Error('Unknown artifact name: ' + artifactName);
}
const finalArtifacts = oldArtifacts;
finalArtifacts[artifactName] = newArtifacts[artifactName];
const newArtifact = newArtifacts[artifactName];
// @ts-ignore tsc can't yet express that artifactName is only a single type in each iteration, not a union of types.
finalArtifacts[artifactName] = newArtifact;
await assetSaver.saveArtifacts(finalArtifacts, artifactPath);
}
}
Expand Down
1 change: 1 addition & 0 deletions lighthouse-viewer/app/src/lighthouse-report-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class LighthouseReportViewer {
* @private
*/
_onPaste(e) {
if (!e.clipboardData) return;
e.preventDefault();

// Try paste as gist URL.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"prettier": "^1.14.3",
"pretty-json-stringify": "^0.0.2",
"puppeteer": "^1.10.0",
"typescript": "3.2.2",
"typescript": "3.5.3",
"uglify-es": "3.0.15",
"url-search-params": "0.6.1",
"whatwg-fetch": "2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion types/externs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare global {
type NonVoid<T> = T extends void ? never : T;

/** Remove properties K from T. */
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type StrictOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

/** Obtain the type of the first parameter of a function. */
type FirstParamType<T extends (arg1: any, ...args: any[]) => any> =
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7585,10 +7585,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==
typescript@3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==

uglify-es@3.0.15:
version "3.0.15"
Expand Down