-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
tests: update to typescript 3.9.7 #11158
Conversation
@@ -15,11 +15,11 @@ const ChromeLauncher = require('chrome-launcher'); | |||
const ChromeProtocol = require('../../../../lighthouse-core/gather/connections/cri.js'); | |||
|
|||
// Load bundle, which creates a `global.runBundledLighthouse`. | |||
// @ts-ignore - file won't exist until `yarn build-all`, but not used for types anyways. | |||
// @ts-ignore - file exists if `yarn build-all` is run, but not used for types anyways. |
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.
the only remaining @ts-ignore
since this is sometimes an error and sometimes not, depending on if the local environment has run yarn build-all
// @ts-ignore - TODO(bckenny): allow optional `throttling` settings | ||
const fcpSimulation = await FirstContentfulPaint.request(metricComputationData, context); | ||
|
||
// Cast to just `LanternMetric` since we explicitly set `throttlingMethod: 'simulate'`. |
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'm surprised this wasn't caught in earlier versions
@@ -297,10 +297,12 @@ function deepCloneConfigJson(json) { | |||
return cloned; | |||
} | |||
|
|||
/** | |||
* @implements {LH.Config.Json} |
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.
Oh, yeah, and @implements
works now! No more implements hacks (see deletion below :)
@@ -27,7 +27,7 @@ jest.mock('../../lib/stack-collector.js', () => () => Promise.resolve([])); | |||
* @param {(...args: TParams) => TReturn} fn | |||
*/ | |||
function makeParamsOptional(fn) { | |||
return /** @type {(...args: RecursivePartial<TParams>) => TReturn} */ (fn); | |||
return /** @type {(...args: Nullable<RecursivePartial<TParams>>) => TReturn} */ (fn); |
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 function is now so super-extra-optional that I question the value of type checking its uses, but w/e :P
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.
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 think i'm missing something.. how does adding null to the type of each parameter item harm the type checking?
That question appears to answer itself :P
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 it's that apparent @brendankenny would you mind still explaining to us plebeians? I have the same question as @connorjclark 😆
why did we need to make individual options nullable but not in a recursive way? did ts really treat fn(null)
as passing a fn(arg: number | undefined)
signature before 3.9.7?
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 it's that apparent @brendankenny would you mind still explaining to us plebeians? I have the same question as @connorjclark 😆
That part was a bit too flippant, my apologies :) I meant in the literal sense that when a type is already a union of a couple of things, and you throw more things in that union, the type may still be technically correct but is likely less and less useful (the limit being any
).
Much more constructively, now 😛...
why did we need to make individual options nullable but not in a recursive way? did ts really treat
fn(null)
as passing afn(arg: number | undefined)
signature before 3.9.7?
It looks like yes, but only in limited circumstances (hence the change being limited to basically this file). Config
allows null
for a lot of its properties (e.g. an -A
config doesn't need passes
), but we (usually) check for those before calling, which this test code isn't doing (like here in Runner
, love that old-school-LH phrasing that probably wouldn't be very helpful to an end user). So it's a legitimate complaint by tsc, even though we know all the test configs we're making have passes
.
Pretty sure the typescript fix was microsoft/TypeScript#37195; see that issue for details.
Buuuut, now that I've looked into this, pretty sure there's a much better fix than what I have here. I'll be in the shame cube :)
@@ -107,8 +107,8 @@ async function begin() { | |||
// copied over to LH.Settings.extraHeaders, which is LH.Crdp.Network.Headers. Force | |||
// the conversion here, but long term either the CLI flag or the setting should have | |||
// a different name. | |||
// @ts-ignore | |||
let extraHeadersStr = /** @type {string} */ (cliFlags.extraHeaders); | |||
/** @type {string} */ |
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.
there are three or four places where we had unnecessary @ts-ignore
s
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.
THANKS FOR ALL HELP
this is a confusing error both in why it would happen in this PR and what needs to be run to fix it :/ (single new line in the generated file) Putting |
fyi: worth reading the list of reasons why one might not always use the new should we start an see: https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame |
yes, that's linked above :) But if the motivation is type checking, I stand by my "strictly better" for lines where either can be used:
The middle one is the only real excuse, and in that case
maybe, but doesn't seem terribly important to me in this case. Maybe other people want it? Very rarely would a |
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.
cool stuff! :)
@@ -511,7 +511,7 @@ class ReportUIFeatures { | |||
}); | |||
|
|||
// The popup's window.name is keyed by version+url+fetchTime, so we reuse/select tabs correctly | |||
// @ts-ignore - If this is a v2 LHR, use old `generatedTime`. | |||
// @ts-expect-error - If this is a v2 LHR, use old `generatedTime`. |
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'm in shock if this code still works on v2 LHRs 😆
@@ -27,7 +27,7 @@ jest.mock('../../lib/stack-collector.js', () => () => Promise.resolve([])); | |||
* @param {(...args: TParams) => TReturn} fn | |||
*/ | |||
function makeParamsOptional(fn) { | |||
return /** @type {(...args: RecursivePartial<TParams>) => TReturn} */ (fn); | |||
return /** @type {(...args: Nullable<RecursivePartial<TParams>>) => TReturn} */ (fn); |
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 it's that apparent @brendankenny would you mind still explaining to us plebeians? I have the same question as @connorjclark 😆
why did we need to make individual options nullable but not in a recursive way? did ts really treat fn(null)
as passing a fn(arg: number | undefined)
signature before 3.9.7?
if (!config.passes) { | ||
throw new Error('gather-runner test configs must have `passes`'); | ||
} | ||
return /** @type {Config & {passes: Array<LH.Config.Pass>}} */ (config); |
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.
now this needs no explanation 🎉 :)
Updates typescript to the latest release.
The main change is the new
@ts-expect-error
directive, which is a strictly better@ts-ignore
. In general all ignored tsc errors should use@ts-expect-error
in the future since it automatically alerts when the ignore needs to be removed if types are tightened or changed in the future, so we won't have ignored cruft sticking around. Maybe we can set up a lint rule to use@ts-expect-error
in the future so we don't have to always remember while coding/reviewing.This PR also