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

misc: remove unneeded type casts #11753

Merged
merged 2 commits into from
Dec 3, 2020
Merged

misc: remove unneeded type casts #11753

merged 2 commits into from
Dec 3, 2020

Conversation

brendankenny
Copy link
Member

follow up to #11752

I did an audit of the other casts I could find and eliminated any that were unnecessary or easy to work around. In the remaining ones, there are some that aren't really casts (typing the initial value of a reduce call), some that are annoyingly necessary (tuples, depending on where they come from/are going), and some ugly ones that are hard to remove but we should get around to fixing at some point.

@brendankenny brendankenny requested a review from a team as a code owner December 2, 2020 23:09
@brendankenny brendankenny requested review from patrickhulce and removed request for a team December 2, 2020 23:09
@google-cla google-cla bot added the cla: yes label Dec 2, 2020
@@ -26,13 +26,13 @@ class FirstMeaningfulPaint extends ComputedMetric {
*/
static async computeObservedMetric(data) {
const {traceOfTab} = data;
if (!traceOfTab.timestamps.firstMeaningfulPaint) {
if (traceOfTab.timings.firstMeaningfulPaint === undefined) {
Copy link
Member Author

Choose a reason for hiding this comment

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

for these, timestamp is allowed to be undefined in the return type, so better to just check timings directly rather than check one and cast the other.

/** @type {[string, LH.Config.AuditDefn]} */
([audit.implementation.meta.id, audit])
));
/** @type {Map<string, LH.Config.AuditDefn>} */
Copy link
Member Author

Choose a reason for hiding this comment

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

improved tuple inference

@@ -80,8 +80,9 @@ class Simulator {
/** @type {Record<number, Set<Node>>} */
this._nodes = {};
this._dns = new DNSCache({rtt: this._rtt});
/** @type {ConnectionPool} */
Copy link
Member Author

Choose a reason for hiding this comment

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

if we're going to @ts-expect-error regardless, might as well not cast :)

@@ -73,7 +73,7 @@ function isPluginURL(url) {
if (parts.length < 2) {
return false;
}
const part = /** @type {string} */(parts.pop());
const part = parts[parts.length - 1];
Copy link
Collaborator

Choose a reason for hiding this comment

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

😆 this is a funny one :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had the same thought :)

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 didn't say all of these were Platonic monuments to type checking, just that the type casts weren't needed :D

lighthouse-core/computed/metrics/first-meaningful-paint.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants