-
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
Expose TypeScript typings #1773
Comments
@ebidel do we want to move to typescript? |
The idea was to test run ts w/ the CLI to start, and then reevaluate. |
Right. I don't think we want to move anything else over given the state of
the team. There doesn't seem to be much benefit in moving more to TS atm.
…On Fri, Feb 24, 2017, 12:39 PM Sam Saccone ***@***.***> wrote:
The idea was to test run ts w/ the CLI to start, and then reevaluate.
I currently do not work on lighthouse as much as I initially did, so this
decision is more up to the maintainers of the lib ;)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1773 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOigD-6qHKptXTtzjXhlAJqPR8VaOiVks5rf1wtgaJpZM4MKwBk>
.
|
I agree with @ebidel but might be good to put this on the next lighthouse meeting |
I'd like to ask that this be revisited. I'm using chrome-launcher in a typescript project, but am getting errors because the d.ts files are not included. It should be a fairly simple change to the tsconfig and package.json to make sure that those are produced and published — I'm more than willing to put in a PR (in fact, I'm in the process of forking & cloning the repo as we speak). |
Hey @devrelm so, you can directly require the typescript code for the launcher (no need for d.ts), will this work for you? yarn add chrome-launcher import {launch} from 'chrome-launcher/chrome-launcher'; |
@samccone Yeah, that'll work. Another alternative could be renaming
Then update "main" in the Anyway, it's not a pressing issue now that I know the workaround. Thanks! |
since folks have run into this twice in two days, i think doing the above makes sense. that work for you, @samccone? |
@devrelm the #2513 fix is shipped in [email protected] update mar 2018: I have an early branch up here with additional types: https://github.com/GoogleChrome/lighthouse/blob/typechecking/typings/externs.d.ts |
@paulirish @wardpeet @ebidel This is great. I can now use the typed interfaces for const flags = { };
const scores = {
'pwa': 90,
'performance': 90,
'accessibility': 90,
'best-practices': 90
};
launchChromeAndRunLighthouse('http://localhost:8000', flags, null)
.then((results: any) => { // <-- this line
results.reportCategories.forEach((cat) => {
if (scores[cat.id]) {
if (cat.score < scores[cat.id]) {
console.log(`Score for '${cat.id}' expected to be ${scores[cat.id]}, but got ${cat.score}`);
} else {
console.log(`Score for ${cat.id} OK, ${cat.score} satisfies theshold ${scores[cat.id]}`);
}
}
});
}); The Will this be available anytime soon? |
The CLI isn't TS anymore. Think this one can be close. |
@brendankenny now that we've got everything nicely typed up what do you think the best strategy is? It seems like there's different levels we could go with this that all have different exposure risk of breaking changes. I'd be inclined to go as small as possible and expose some LHR-lite style types for the response. |
Thanks for bumping it back up, Patrick. |
Yeah, agreed with this. We can start with the LHR and the callable interface to |
Sorry, is this fixed in lighthouse 4.1.0? Looking at this project: https://github.com/AndrejsAbrickis/lighthouse-azure-devops as described here: He's using an alpha version of 4.0.0 in his package.json:
and he's importing as so:
But this isn't working in 4.1.0. I'm thinking these alpha changes weren't rolled into the release? |
@taji that "alpha" version is actually identical to version In v4, you should be able to achieve the same effect by replacing /// <reference path="./node_modules/lighthouse/typings/externs.d.ts"/> with /// <reference path="./node_modules/lighthouse/types/externs.d.ts"/> We're hoping to offer a better solution sometime in the future that doesn't require this hacky reference though. |
TS typing would be especially useful for plugins! I tried hard to make it work in https://github.com/treosh/lighthouse-plugin-field-performance |
|
Also interested in this. Any way to export the current types in the repo or put into an @types package? |
Moving to types repo gives us extra maintenance overhead so I think we don't want to go that route but exposing it from our package seems a good idea |
if your types are not generated from code, I suggest keep the types in DefiantlyTyped. Almost every lib that decided to publish handwritten types has regretted it. |
I don't think we were ever going to write types manually. We were waiting for TS 3.7 to generate types from JSDoc. @brendankenny should we move on this now? |
it was still buggy the last time I tried it, but maybe it works now? We have a large amount of stuff we would probably not want to have in end-user types, but maybe there's also a nice way to do that. We also need to move off types in a global namespace (we need to do that for a few reasons, actually), but I wasn't sure how well that would go over with y'all :) |
What would that look like? For example, to reference Sounds like we are a few steps removed from doing this properly. For now, let's just upgrade to the latest TS. |
Would love to consume these types, is there anything I can do to help move this along? |
Any updates? |
Anything? |
Since there has been no response for quite a while, would it be a reasonable suggestion to programmatically edit the contents of lighthouse's package.json in order for the |
same issues |
This comment was marked as spam.
This comment was marked as spam.
Create a /// <reference types="lighthouse/types/global-lh" />
declare module 'lighthouse' {
function lighthouse(
url: string,
options: Partial<LH.CliFlags>,
): Promise<LH.RunnerResult>;
export = lighthouse;
} Then in your {
"compilerOptions": {
/* ... */
},
"files": ["lighthouse.d.ts", /* ... */],
"include": ["lighthouse.d.ts", /* ... */]
} |
The types should be exposed in Lighthouse 10.0 with #14441 |
I see some TypeScript files here and there... is this written in TypeScript? Even if it's not, all of JavaScript code is nicely annotated (Thanks Closure Compiler!). Can you expose the typings via
typings
key inpackage.json
? It would be great for TypeScript users and VSCode editor users thanks to Automatic Type AcquisitionThe text was updated successfully, but these errors were encountered: