misc: remove unneeded type casts#11753
Merged
devtools-bot merged 2 commits intomasterfrom Dec 3, 2020
Merged
Conversation
brendankenny
commented
Dec 2, 2020
| static async computeObservedMetric(data) { | ||
| const {traceOfTab} = data; | ||
| if (!traceOfTab.timestamps.firstMeaningfulPaint) { | ||
| if (traceOfTab.timings.firstMeaningfulPaint === undefined) { |
Contributor
Author
There was a problem hiding this comment.
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>} */ |
Contributor
Author
There was a problem hiding this comment.
improved tuple inference
| /** @type {Record<number, Set<Node>>} */ | ||
| this._nodes = {}; | ||
| this._dns = new DNSCache({rtt: this._rtt}); | ||
| /** @type {ConnectionPool} */ |
Contributor
Author
There was a problem hiding this comment.
if we're going to @ts-expect-error regardless, might as well not cast :)
connorjclark
approved these changes
Dec 2, 2020
patrickhulce
approved these changes
Dec 3, 2020
| return false; | ||
| } | ||
| const part = /** @type {string} */(parts.pop()); | ||
| const part = parts[parts.length - 1]; |
Collaborator
There was a problem hiding this comment.
😆 this is a funny one :)
Collaborator
There was a problem hiding this comment.
I had the same thought :)
Contributor
Author
There was a problem hiding this comment.
I didn't say all of these were Platonic monuments to type checking, just that the type casts weren't needed :D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
reducecall), 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.