-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Conversation
@@ -26,13 +26,13 @@ class FirstMeaningfulPaint extends ComputedMetric { | |||
*/ | |||
static async computeObservedMetric(data) { | |||
const {traceOfTab} = data; | |||
if (!traceOfTab.timestamps.firstMeaningfulPaint) { | |||
if (traceOfTab.timings.firstMeaningfulPaint === undefined) { |
There was a problem hiding this comment.
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>} */ |
There was a problem hiding this comment.
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} */ |
There was a problem hiding this comment.
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 :)
lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js
Outdated
Show resolved
Hide resolved
@@ -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]; |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
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.